Example input string:
(F1 (F2 X (Y) Z) (F3 A B)
What i want to match: \w+ that is not preceded by a ( unless also followed by )
In this case: X, Y, Z, A, and B
A temporary work-around for now (which I know will give me issues later) is /\(\w+\)| \w+/, but as it also matches whitespaces, it will cause problems further down the road, especially when it gets to the point of substituting the matches.
I have done some experimenting in the area of negative lookbehind in the form of:
/(?!=\()\w+/
…but i can’t seem to find a way of combining it with “not preceeded by (“
Just to be clear:
- The matches in this case are all single letter, but actual data may be multiple characters and may not even be alphanumeric.
- No whitespaces or parentheses can be a part of the returned match.
Try this:
See it here in action: http://regexr.com?2vnri
Actually, this might be what you are looking for:
See it here in action: http://regexr.com?2vnro