If I try this code:
<?php
$greets1="hello jack"; $greets2="hi john";
preg_match('/(hello )((?(?=jack)j))/',$greets1,$result);
?>
It writes hello
in $result[1]
and j
in $result[2]
.
If I change the 3rd line to:
preg_match('/(hello )((?(?=jack)there))/',$greets1,$result);
It writes nothing in both $result[1]
and $result[2]
. Why is that?
And also: how can I write the space character in the lookahead? I tried in many ways:
preg_match('/(hello)((?(?= jack)j))/',$greets1,$result);
preg_match('/(hello)((?(?=\ jack)j))/',$greets1,$result);
preg_match('/(hello)((?(?=\\\ jack)j))/',$greets1,$result);
No one of these worked.