"remove text between parentheses php" Answer’s

0
$string = "ABC (Test1)";
echo preg_replace("/([^)]+)/","",$string); // 'ABC '

preg_replace is a perl-based regular expression replace routine. What this script does is matches all occurrences of a opening parenthesis, followed by any number of characters not a closing parenthesis, and again followed by a closing parenthesis, and then deletes them:

Regular expression breakdown:

/  - 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
Wednesday, March 31, 2021
 
CBroe
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :