Regular expression to remove string between brackets

Viewed 794
  1. My string is like this : Name (CLOSED)
  2. My string is like this : Name (CLOSED 0FF)
  3. My string is like this : Name (CLOSED OF)
  4. My string is like this : Name (DEC'D)

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?

5 Answers

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
Related