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….

Comment Form

Leave a Reply

Your email address will not be published. Required fields are marked *



Latest comments

    Fatal error: Uncaught Error: Call to undefined function split() in /home4/nos/public_html/ Stack trace: #0 /home4/nos/public_html/ mdv_recent_comments() #1 /home4/nos/public_html/ include('/home4/nos/publ...') #2 /home4/nos/public_html/ include('/home4/nos/publ...') #3 /home4/nos/public_html/ require_once('/home4/nos/publ...') #4 /home4/nos/public_html/ require('/home4/nos/publ...') #5 {main} thrown in /home4/nos/public_html/ on line 72