I have the following string:
string = "x OPTIONAL() y z(..., ...)"
Where OPTIONAL() is indeed optional, so the string may also be:
string = "x y z(..., ...)"
Using regular expressions, I want to match the string until the first one of these characters is found:
([{;=,
Beware that OPTIONAL() includes one of the characters above, but the search should not stop at OPTIONAL(.
So I would like to have:
x OPTIONAL() y z
Or:
x y z
I'm currently using:
re.search("[ \t\n\r\f\v]*(OPTIONAL\(\))?([^([{;=,]+)", string)
And the match properly stops at:
x y z
when OPTIONAL() is not in the string.
However, with OPTIONAL() in the string, the match stops at:
x OPTIONAL