-2

Why is this regex is not removing everything in the parenthesis?

Regex expression:

[\(\[].*?[\)\]]

Test string:

Firstname Lastename @username ([tesstt](weblinke))

Result of the expression:

Firstname Lastename @username )

It leaves the closing parenthesis.

Jcheong
  • 21
  • 6

1 Answers1

0

What you want to do is to substitute anything (or nothing) within parentheses with nothing.

For example, in Vim, it would be:

:s/([A-Za-z0-9\.]*)//g

Or you could use sed:

sed -i 's/([A-Za-z0-9\.]*)//g' name_of_file.txt

There are other ways to accomplish it as well, but the general pattern is the same. Note, the way I have it limits the stuff between the parentheses to alphanumeric characters and/or periods, but you can add other special characters if you need to. (example, an exclamation point)