php - replace string but not a specific word that contains that string -


suppose have string

$string = 'this gal_s, not 1_s not 2_s not 3_s'; $find = '_s'; $replace = ''; 

i woul return

"this gal_s, not 1 not 2 not 3" 

so word gal_s not affected

is possible?

you can use preg_replace negative lookbehind this:

$repl = preg_replace('/(?<!\bgal)_s/', '', $str); 

live demo: http://ideone.com/getsv3


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -