$string = "ABC (Test1)"; echo preg_replace("/\([^)]+\)/","",$string); // 'ABC '
preg_replace is the usual perl-based regular expression replacement routine. What this script does is match all occurrences of the opening bracket, followed by any number of characters, not the closing bracket, and the closing bracket again, and then remove them:
Regular Expression Distribution:
/ - opening delimiter (necessary for regular expressions, can be any character that doesn't appear in the regular expression \( - Match an opening parenthesis [^)]+ - Match 1 or more character that is not a closing parenthesis \) - Match a closing parenthesis / - Closing delimiter
cmptrgeekken Feb 01 '10 at 2:46
source share