0

I have a measure device that creates samples in the following format:

V GL020(1)=20110117161703

another example:

V GLXX011(10)=ADEF=*GFSDAS

What I'm trying to do is to create a regex expression that returns GL020 / 1 / 20110117161703 for the first example and GLXX011 / 10 / ADEF=*GFSDAS for the second example.

I found a regex expression that reliably matches the fist two required parts:

.*?(?<Field>(?:[a-z][a-z]*[0-9]+[a-z0-9]*)).*?(?<Count>\d+)

However, i'm still missing the part after the first "=". I don't know if it is important but the part after the first "=" might include characters like "=" itself.

2
  • You're having trouble matching everything after the equals-sign? Then match against exactly one equals-sign + everything that follows (which would include more equals-signs of course) Commented Apr 3, 2012 at 11:18
  • Couldn't you just skip the first two characters (V ) and replace ( and )= with ` / ` (and if it matters, just their first occurrences)? Commented Apr 3, 2012 at 11:21

3 Answers 3

4

You could use an expression like:

(\w+)\((\d+)\)=(\S+)

Giving you the substrings that you want in the first, second and third capturing groups.

Sign up to request clarification or add additional context in comments.

2 Comments

lol. wow. so easy. i spent hours on that one. :((. thank you very much. the third capturing group might include spaces as well. how would i handle that?
@lightxx, if you just want to capture everything after the first =, you could change \S+ to .+. (. does not match new lines unless you use the s flag.)
1

Try using this one:

([^\(|\s]+)\((\d+)\)=([\w|\=|\*]+)

1 Comment

@Qtax it was quicker to add here a newline in the answer than to explain in a comment, what should be corrected.
0

please use this regex:

(?<first>\w+)\s(?<second>\w+)(?<third>\(\d+\))=(?<forth>.*)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.