Reputation: 2561
I want to remove both brackets and string inside the brackets, to get only : Name
I'm using this URL http://regexr.com/ and I have written regx like this: ([()]CLOSED)
However, the last bracket is not getting selected. What am I doing wrong?
Upvotes: 2
Views: 2160
Reputation: 18611
Remove parens at the end of string:
\s*\([^()]*\)$
See regex proof.
EXPLANATION
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\( '('
--------------------------------------------------------------------------------
[^()]* any character except: '(', ')' (0 or more
times (matching the most amount possible))
--------------------------------------------------------------------------------
\) ')'
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
Upvotes: 1
Reputation: 8332
Don't know why Estebans answer doesn't work for you, but at least this should:
Replace
\s*\([^)]*\)
with nothing (empty string).
See it here at regex101 (it appears regexr doesn't save the substitution string so I used regex101 instead).
Upvotes: 1
Reputation: 1815
You can use this regex : ([\s]*[(][^)]*[)])
This will match any space character following by (
following by any character which is not )
and )
If what you want is specifically the CLOSED
text, just use : ([\s]*[(]CLOSED[)])
Upvotes: 0