Click here to Skip to main content
15,894,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I'm trying to build a regular expression that later on I can parse all the values from a string as follows:

VB
FFD:000D6F0002542F8D,531F,-82,FF
FFD:000D6F00015D518F,B643,-70,FF
FFD:000D6F0000D5493B,9915,-71,FF
FFD:000D6F00015D5CE1,9F69,-83,FF
FFD:000D6F000257F6CF,4D1F,-60,FF
SED:000D6F0000BA1A7E,63AA,-70,FF
FFD:000D6F0000D5F442,7CDE,-84,FE
FFD:000D6F0000BA19B9,0000,-59,FF
FFD:000D6F00024D00E5,D63E,-62,FF
FFD:000D6F0000D5F277,0290,-81,FF
FFD:000D6F0000D57E63,3B1F,-84,FB
FFD:000D6F000257F5EC,B2BE,-56,FF
FFD:000D6F00015CA322,9EA6,-68,FF


RegEx that I've built so far:
[[(COO)][(FFD)][(RFD)][(MED)][(SED)][(ZED)]]+:[0-9[A-F]]{16}+,+[0-9[A-F]]{4}+,+[(\-\d)]+,+[0-9[A-F]]{2}

This website has been very helpful testing my expression in java:
http://www.regular-expressions.info/email.html[^]

It looks like it's finding all expressions but it's not returning any matches why is that?

Thank you very much.
Posted
Comments
Peter Leow 28-Jan-14 7:33am    
If you want to extract numbers from the string? try \d+
Member 4384663 28-Jan-14 11:42am    
Thank you very much Peter for your solution. It's very nice to see visually the regex. Just to complement the solution: to make easier to parse the string I grouped every element with parenthesis.

final: (COO|FFD|RFD|MED|SED|ZED):([0-9A-F]{16}),([0-9A-F]{4}),(\-\d+),([0-9A-F]{2})

1 solution

Your regex has some syntax errors. Like []{16}+ and some logic errors...

See this one:
(COO|FFD|RFD|MED|SED|ZED):[0-9A-F]{16},[0-9A-F]{4},\-\d+,[0-9A-F]{2}


Now to explanations...
(COO|FFD|RFD|MED|SED|ZED)
- find one of these character sequences
[0-9A-F]{16}
- 16 characters from the hexadecimal range
\-\d+
- a minus (-) sign and at least one digit

See it here visually:http://www.regexper.com/#(COO%7CFFD%7CRFD%7CMED%7CSED%7CZED)%3A%5B0-9A-F%5D%7B16%7D%2C%5B0-9A-F%5D%7B4%7D%2C%5C-%5Cd%2B%2C%5B0-9A-F%5D%7B2%7D[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900