I need to extract the string
MAC:BFEBFBFF000006FB00:1E:37:54:AE:C8
out of
ADMIN:1EXT:0NOR:0OUT:1PRI:1BAT:1MOD:1MAC:BFEBFBFF000006FB00:1E:37开发者_开发技巧:54:AE:C8
The regular expression i use is
(MAC:[A-Z0-9]{10})+
But still i do not get the intended result
(MAC:[A-Z0-9:]+)
will match: MAC:BFEBFBFF000006FB00:1E:37:54:AE:C8
.
(MAC:[A-Z0-9]+)
will match: MAC:BFEBFBFF000006FB00
.
(MAC:(([A-F0-9]+:*)))
Mac address are in hexadecimal characters...so it's A-F and not A-Z.
PS: I've tested the expression.
The expression states that you will have multiple sequences of 10 characters of [A-Z0-9] which isn't the case four your desired string.
Your regex matches
MAC:BFEBFBFF00
If the input is like your example, you could use a simple regex like this
MAC:[A-F0-9:]+
Otherwise, you could do something like this if you want to be very specific
MAC:[A-F0-9]{18}(:[A-Z0-9]{2}){5}
As pointed out by The Elite Gentleman you can get by using just A-F, if you're looking for hex numbers.
精彩评论