I have the following code:
<?php
$data="000ffe-fcc9f4 1 000fbe-fccabe";
$pattern='/([0-9A-F]{6})-([0-9A-F]{6})$/i';
echo "the pattern we are using is: ".$pattern."<BR>";
preg_match_all($pattern,$data,$matches, PREG_SET_ORDER );
print_r($matches[0]);
?>
I don’t understand why it’s not finding both mac addresses as matches.
Here’s what the output on the page looks like:
the pattern we are using is: /([0-9A-F]{6})-([0-9A-F]{6})$/i
Array ( [0] => 000fbe-fccabe [1] => 000fbe [2] => fccabe )
I was expecting that element [0] would contain both 000ffe-fcc9f4 and 000fbe-fccabe.
Can you tell me what I’m doing wrong?
Thanks.
The reason it isn’t finding both is because you have a
$at the end of your regex which means it will only match that pattern at the end of the string.Try changing
$patternto/([0-9A-F]{6})-([0-9A-F]{6})/iand that should match both.