Search code examples
regexeclipsereplacetext-formatting

How to use find / replace for starts with a character than ends with a character


I have 800 line text in my document in Eclipse. I want to format my code like below.

Hi hello (how are you?) -> Hi hello

Another example (5895489 hi again) -> Another example

as you can see I want to delete starts with "(" and ends with ")".

How can I do it in Eclipse with regular expressions?


Solution

  • You can use the following, the replacement value will be an empty value.

    search: \s*\([^)]*\)
    replace:
    

    Regular expression:

    \s*             whitespace (\n, \r, \t, \f, and " ") (0 or more times)
     \(             '('
      [^)]*         any character except: ')' (0 or more times)
     \)             ')'
    

    Note: I added the \s* to match for leading whitespace just in case so that it don't leave trailing whitespace after the replacement is made.