Jump to content

[SOLVED] preg_match almost done, need a little help


solarisuser

Recommended Posts

Hi All,

 

I have a mac address (11:22:33:44:55:66) for example.. I need to remove the last three groups, leaving just 11:22:33

 

So far I have come up with:

 \[^\:]+)

 

But its not really right...

 

In addition, I need to add a "0" (zero) digit to single groups in a mac address like this: (0:aa:3:aa:bb:2)

 

Any help would be much appreciated!

<pre>
<?php
$tests = array(
	'11:22:33:44:55:66',
	'0:aa:3:aa:bb:2'
);
foreach ($tests as $test) {
	$test = preg_replace('/(?::\d+){3}\z/', '', $test);
	$test = preg_replace('/\b(?=\d\b)/', '0', $test);
	echo $test, '<br>';
}
?>
</pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.