I'm looking to try and combine 2 regex expressions.
$test = preg_replace('/\[.*?\]/', '', $test);
I use this to remove any square brackets and words in between the brackets..
$test = preg_replace ('/[\[\]=]+/', '', $test);
I use this to strip any = [ ] symbols from my string.
doing this individually seems to be fine, but I'd like to combine them. Any ideas how I can do that.. everything I've tried has broken both..
Thanks
Use an alternation:
$test = preg_replace('/\[.*?\]|[\[\]=]/', '', $test);
The ordering is here important, so that at first matching brackets, and their content, are removed. This should work fine as long as there are no nested brackets.
So, this expression will match either \[.*?\]
OR [\[\]=]
Simplest answer is to use an or:
'/\[[^\]]*\]|[\[\]=]+/'
Notice that I also changed the inner pattern in the first string. I'm not sure if the backslash is needed there.