Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Fixed RegExp #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Datasift/IfconfigParser/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ public function getDelimiter() {
* @return string
*/
public function getRegex(){
return "^(?<interface>(?:[^\s]+)).*?(?:inet addr:(?<ip_address>(?:\d+\.?){4})|$)";
return "^(?<interface>(?:[^\s]+)).*?(?:inet (?:addr:)?(?<ip_address>(?:\d+\.?){4})|$)";
}

/**
* parse
*
* @param mixed $input ifconfig input to parse
*
* @return string
* @return array
*/
public function parse($input){
$adapters = preg_split("/" . $this->getDelimiter() . "/s", $input, null);
$adapters = preg_split('/' . $this->getDelimiter() . '/s', $input, null);
$vals = array();
foreach ($adapters as $int){
preg_match("/".$this->getRegex()."/s", $int, $output);
preg_match('/' . $this->getRegex() . '/s', $int, $output);
$vals[] = $output;
}

Expand All @@ -97,7 +97,7 @@ protected function format($vals){
$formattedVals = array();

$expectedFields = array(
"interface", "ip_address"
'interface', 'ip_address'
);

foreach ($vals as $v){
Expand All @@ -112,7 +112,7 @@ protected function format($vals){
}

// Remove any entries that don't have an interface
$formattedVals = array_filter($formattedVals, function($val){
$formattedVals = array_filter($formattedVals, static function($val){
return isset($val['interface']);
});

Expand Down