php - preg_replace() replace only one pattern but match another pattern -
i trying replace string preg_replace()
i want replace 1 pattern 'bbb' want match pattern , 2 more ('aaa' , 'ccc') example
input : 'zzz aaa bbb ccc xxx' pattern match : 'aaa bbb ccc' output : 'aaa ccc'
is possible make happen preg_replace() without invoking preg_match()
you can use:
echo preg_replace('/.*?(\baaa\b) +\bbbb\b +(\bccc\b).*/', '$1 $2', 'zzz aaa bbb ccc xxx'); //=> aaa ccc
Comments
Post a Comment