suppose I have a string
$string = 'this is my gal_s, not my 1_s not 2_s not 3_s';
$find = '_s';
$replace = '';
I woul like to return
"this is my gal_s, not my 1 not 2 not 3"
so the word gal_s is not affected
Is this possible?
You can use preg_replace with negative lookbehind like this:
$repl = preg_replace('/(?<!\bgal)_s/', '', $str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With