Search code examples
regexparentheses

Regex Keep All After parentheses ")"


I want to remove with regex everything before ")" and the ")" but keep the rest.

This what I have done so far. This does what I want except it keeps the ")" which I don't want.

^[^\\)]+

Example Text:

#tags (word) this a example where i run the regex.

After Regexing I have:

) this a example where i run the regex.

I want:

this a example where i run the regex.

I need to remove the ")" or ") " if it has space after the ")".


Solution

  • Since I don't know which language you're using you'll want to escape the backslashes appropriately for your language.

    The regex you want is ^[^\)]*\) ?. See example on regex101.com

    The ^ anchors to the beginning of the string. [^\)] finds any character that's not a ). The * matches that 0 or more times. The \) matches a literal paren. And the <space>? matches 0 or 1 spaces. <space>* would match 0 or more spaces.