alexandernst
alexandernst

Reputation: 15109

Matching as less as possible (greedy-like)

I have a string that might terminate with multiple ) characters and possibly followed by some non-character symbols (,.:; etc)

I'm testing with this string this is foo bar)),: and this regex -> \){1}\W*?$ but this matches both ). How can I match only the last ) (no matter how many are there) ?

Upvotes: 1

Views: 79

Answers (1)

anubhava
anubhava

Reputation: 785156

this regex -> \){1}\W*?$ but this matches both ). How can I match only the last ).

You can use negated character class:

\)[^\w)]*$

[^\w)] will match anything but a ) or any word char.

Upvotes: 1

Related Questions