Regex parsing issue

39 views
Skip to first unread message

Chap Cory

unread,
Jul 30, 2013, 10:40:57 AM7/30/13
to comman...@googlegroups.com
The question:
I am receiving strings from my Autonomics  Which is used for messagebox popups.
In each case, there is a GUID, Header, Description followed by either three field sets (Case 1), or two Field Sets (Case 2).
(field sets are between the 0's)

Shouldn't I be able to make the Regex have an Optional section for the third field?
I tried bracket question mark around the last regex group, didn't work (in the Guidesigner regex tester)

Regex:  UI=MessageBox.\{(.*)\}.\"(.*)\".\"(.*\?)\"..*\d.\"(.*)\".\"(.*.\\\".*\\\").*\d.\"(.*)\".\"(.*)\".*\d.\"(.*)\".\"(.*.\\\".*\\\")\.*"   (thanks to original author, Terence)

Case 1:  UI=MessageBox {122f5622-e532-4940-b86f-642eae65a7cc} "Edit Pandora station 'Bullitnuts Radio'." "What would you like to do to this station?" 30 "Delete the station" "AckButton 122f5622-e532-4940-b86f-642eae65a7cc \"Delete the station\"" 0 "Edit the station" "AckButton 122f5622-e532-4940-b86f-642eae65a7cc \"Edit the station\"" 0 "Cancel" "AckButton 122f5622-e532-4940-b86f-642eae65a7cc \"Cancel\"" 0


Case 2:  UI=MessageBox {122f5622-e532-4940-b86f-642eae65a7cc} "Edit Pandora station 'Bullitnuts Radio'." "What would you like to do to this station?" 30 "Delete the station" "AckButton 122f5622-e532-4940-b86f-642eae65a7cc \"Delete the station\"" 0 "Edit the station" "AckButton 122f5622-e532-4940-b86f-642eae65a7cc \"Edit the station\"" 0

Of course, I could build two regex's for each case, but that seems inelegant.
Thanks as always,
Chap

Jarrod Bell

unread,
Jul 30, 2013, 8:56:01 PM7/30/13
to comman...@googlegroups.com
http://regex101.com/r/qH4hI6

Crafted the regex a little more cleanly I think, using lazy (non-greedy) capture groups to ensure they end where they are meant to.
And enclosed the optional data in a non-capturing group.

The site linked to is a GREAT way to test your regex and see the result, and an explanation of what it's actually doing.

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


On 31/07/13 12:40 AM, Chap Cory wrote:
Reply all
Reply to author
Forward
0 new messages