I am trying to remove everything between two characters, including the two characters, from a string using regex in php. I tried using the answer on this page so now I have a line in my php file which looks like this :
$message = preg_replace('\[[^\]]*]', '', $message);
The problem is I get this error:
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
How can I fix this?
Regular expressions in PHP need to be delimited:
Check out this documentation.
Also as a side note, you don’t need to escape the closing
]if it is the first character in a character class:(Whether that is more readable in this case is debatable. But it’s good to know.)