solarisuser Posted July 6, 2007 Share Posted July 6, 2007 Hello All, I have data in the form of "0:1:22:33:44:55" and "00:11:22:33:44:55". What I would like to figure out is how to have regex modify the first example to add a "0" in front of any single digit or alpha character, and leave the parts with two numbers or alphas alone. The ":" is always going to be a delimiter. For example, the first example above should convert to "00:01:22:33:44:55". Any assistance would be appriciated - I have basic regex experience and use google to figure out basic stuff but I dunno how I would start this. Thanks Quote Link to comment Share on other sites More sharing options...
rea|and Posted July 6, 2007 Share Posted July 6, 2007 Mac address' are in hexadecimal rapresentation, if i'm not wrong, so you have also to consider letteral characters, something like this echo preg_replace('/\b[A-F0-9]\b/i','0$0',$mac); Quote Link to comment Share on other sites More sharing options...
solarisuser Posted July 6, 2007 Author Share Posted July 6, 2007 Mac address' are in hexadecimal rapresentation, if i'm not wrong, so you have also to consider letteral characters, something like this echo preg_replace('/\b[A-F0-9]\b/i','0$0',$mac); it looks good to me - thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.