How to replace string in parentheses using regex

How to replace string in parentheses using regex

June 27, 2012 | In: How to do, Linux, php, Regular Expression, web development

PHP, Java and other languages provide replace all functionality to replace any character by any specific character. But REGEX is best method to replace or remove any specific value using pattern.

Suppose, we have input string is

$xyz = "This is my best (friend)";

and we want to remove words from “()”.

So it so straight forward and simply:

"\\(.+?\\)"

That’s it….