Regular Expression match to stop at a 2 characters combination or End of String

theskiguy

New member
Joined
Mar 18, 2013
Messages
3
Programming Experience
3-5
Hi Everyone:

Hopefully I'm posting this in the right section. I looked for a separate REGEX section but didn't see one. I need some help with a REGEX match. I am trying to match the following with this regex and return everything between the $ and the ") or end of line. The REGEX below works but stops after either a " or a ). I would like it to only stop after a combination of both or the end of the line.. This way it won't stop at the (8) on the 7th test below

\$\s?([^"\)]*)



N6942 MSG ("$ PROGRAM STOP")
N16 MSG("$SETUP PER SETUP SHEET")
MSG("$SETUP PER SETUP SHEET")
N16 ;$SETUP PER SETUP SHEET
;$SETUP PER SETUP SHEET
;$ SETUP PER SETUP SHEET
;$SETUP PER SETUP SHEET (8) TIMES
; THIS SHOULD NOT MATCH

Thanks,
 
I would just write the whole pattern and name the group of interest, then get the Match.Groups(name).Value

If you're matching this as a multiline text (RegexOptions.Multiline) to exclude newline chars:
VB.NET:
Dim pattern = "\$(?<m>.+?)(\""\)|\r)"
If you're matching this line by line:
VB.NET:
Dim pattern = "\$(?<m>.+?)(\""\)|$)"
Groups("m") has the matching strings.
 
Back
Top