solarisuser Posted September 26, 2007 Share Posted September 26, 2007 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! Link to comment https://forums.phpfreaks.com/topic/70811-solved-preg_match-almost-done-need-a-little-help/ Share on other sites More sharing options...
effigy Posted September 27, 2007 Share Posted September 27, 2007 <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> Link to comment https://forums.phpfreaks.com/topic/70811-solved-preg_match-almost-done-need-a-little-help/#findComment-356510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.