tags:

views:

38

answers:

4

Hello 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

Please help !!

+1  A: 

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.

Brian Rasmussen
Glad to have helped Brian.
The Elite Gentleman
+2  A: 

(MAC:[A-Z0-9:]+) will match: MAC:BFEBFBFF000006FB00:1E:37:54:AE:C8.
(MAC:[A-Z0-9]+) will match: MAC:BFEBFBFF000006FB00.

Darin Dimitrov
A: 

Thanks a lot it works !!

constant learner
Don't submit an answer to your question. Just up vote and/or accept an answer please.
Brian Rasmussen
+1  A: 
(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 Elite Gentleman
That is a good point! I just took for granted that the OP meant A-Z.
Brian Rasmussen