PHP This is an oversimplification of a problem to get to the point.
I am trying to use preg_replace() on a $string that contains a name. I want to replace an O with an E in the first name only, if there is one. So I want to stop looking when I encounter the first space. There may be multiple spaces in the full name, but I am only looking at the first part of the name.
$string = preg_replace('/O/', 'E', $string);
How do I add code to tell it to stop at the first space?
explode(), perform the replacement on the first element, then put it back together withimplode().preg_replace()using a lookbehind, but this will be clearer.$string =~ s/xxx/yyy/to$string = preg_replace('/xxx/', 'yyy', $string);and replacexxxandyyywith whatever you'd do in Perl.