Only remove numbers inside parentheses (brackets)

2019-06-21 04:23发布

Using the code below, I can turn Number123(45) into Number.

$string = 'Number123(45)';
$string2 = preg_replace('/[0-9]+/', '', $string);
echo $string2;

How would I only remove the numbers inside parentheses (brackets) so that the output is Number123()?

1条回答
神经病院院长
2楼-- · 2019-06-21 04:41

Include the parentheses in the pattern, like so:

$string = 'Number123(45)';
$string2 = preg_replace('/\([0-9]+\)/', '()', $string);
echo $string2;

Output:

Number123()

查看更多
登录 后发表回答