Regex - Match a string outside of the parentheses
How do I match any
e
which's not inside of the parentheses?
I have created a pattern to do it, but it doesn't seem to work properly. It should store (
s and remove )
s, so that an e
that is outside of the parentheses is matched e.g. ()()()e
, but e
inside of the parentheses isn't e.g. (e)
.
https://regex101.com/r/3m6ZUc/1
1 Reply
Even though quite a similar pattern finds them properly.
https://regex101.com/r/BE4OLO/1
Oh, was writing the answer and discord suddenly crashed.
Yes, parentheses can be nested.
E.g.
In this case just
e
s ouside of the parentheses should be matched
so (e)
is inside of them, ()e
- ouside
And the format can be wrong too.
in this case there're not enough parantheses, no e
should be matched
In this case I don't really care whether e
is matched or not. E
is probably outside of the parantheses, but the format is wrong and I'm gonna throw an error for this input. So it doesn't matter whether e
is matched here
Yes, the purpose of the pattern is just to match the e
outside of the brackets. It shouldn't include looking for errors
so how would your recommend to implement it?
I see, I guess I got a bit too excited about using regex in all the cases
I'll use this variant then
Thank you 🙂