I have this .NET regex:
^(?<prefix>('[^']*'))\s(?<attrgroup>(\([^\)]*\)))\s(?<suffix>('[^']*'))$
It properly matches the following strings:
'some prefix' ('attribute 1' 'value 1') 'some suffix' 'some prefix' ('attribute 1' 'value 1' 'attribute 2' 'value 2') 'some suffix'
It fails on…
'some prefix' ('attribute 1' 'value (fail) 1') 'some suffix'
…due to the right paren after ‘fail’.
How can I modify my regex so that the attrgroup match group will end up containing ‘('attribute 1' 'value (fail) 1')‘? I’ve been looking at it for too long and need some fresh eyes. Thanks!
Edit: attrgroup won’t ever contain anything other than pairs of double-quoted strings.
my, untested guess:
hereby I’ve replaced
with
I assumed everything within the parenthesis is either between double quotes, or is a whitespace.
If you want to know how I came up with this, read Mastering Regular Expressions.
ps. if I’m correct, then this will also validate attribute group as pairs of quoted string.