Regex Matching MAC Address
Solution 1:
You have to remove the anchors
^
and$
You have to add
a-z
in your character set.. or make the searches case insensitive with(?i)
(i modifier)
Following will work:
([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})
See DEMO
Solution 2:
The anchors ^
and $
say to only match strings that are MAC addresses, not the parts within strings that are MAC addresses. Also, your regex uses capital letters (A-F), but the MAC addresses in that string are lowercase. Are you doing a case insensitive search (if using the re
module, that would be re.IGNORECASE
)? Try turning on case-insensitive search or add "a-f" after the A-F.
On a side note, there is no reason to include the :
in brackets ([:]
), because that means "match any one of this one character". You can just use :
directly.
With case insensitive off you should be able to use this:
([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})
With case insensitive on:
([0-9A-F]{2}:){5}([0-9A-F]{2})
Post a Comment for "Regex Matching MAC Address"