Menu
Hello,
I’m trying to remove square brackets and everything between them from a string, using regular expressions.
$string = ‘1 [any12text#!@] 2 [sfd$#12] 3’;
$string = preg_replace(‘/[]
echo $string;
Outputs: 1 3
Instead of: 1 2 3
I understand that it replaces everything, including the inner brackets, from the first to the last brackets.
I also know that the ^ sign is used to specify something you don’t want in a patten, so it should have been something like ^[^]
Any suggestions?
Thanks in advance.