in reply to Re: Re: Re: Converting MAC Address
in thread Converting MAC Address
The :? was only there to remove the : not to delimit (correct word i hope), where the regular expression would stop matching but to remove it if it existed after a string of characters in [0-9A-F]. Thus the (?::|$) is unnecassary, as it will stop when it hits something outside [0-9A-F] anyway, whether it is a colon or the end of the line.
After further thought the reason:
does not work how it was intended is because ([0-9A-F])+ in the B8 part (the other parts worked because of a fluke of circumstance, but had they all been B8 the error would have been glaringly apparent), but I digress, the reason it did not work for the B8:, is that it first captures the B but the + makes it want more so it continues to with the 8 but since we don't have a + on the inside(ie. ([A-F0-9]+)) the B is tossed, well technically is part of the successful match, but the due to the placement of the + the $1 is now 8. Now, it tries for something else in this character class, but since there is nothing it continues to the next part of the expression, and since the : is the next thing it needs to match (if it is there, hence the ? after the :), it matches successfully, and life goes on, and if no one else learned anything from my spiel, I did, and that counts for something$foo =~ s/([0-9A-F])+:?/length($1) < 2?"0$1":$1/ge;
-enlil
|
|---|