このコードを試してみると:
<?php
$greets1="hello jack"; $greets2="hi john";
preg_match('/(hello )((?(?=jack)j))/',$greets1,$result);
?>
とに書いhello
て$result[1]
あります。3行目を次のように変更すると:j
$result[2]
preg_match('/(hello )((?(?=jack)there))/',$greets1,$result);
$result[1]
とには何も書きません$result[2]
。何故ですか?
また、先読みでスペース文字を書くにはどうすればよいですか? 私は多くの方法で試しました:
preg_match('/(hello)((?(?= jack)j))/',$greets1,$result);
preg_match('/(hello)((?(?=\ jack)j))/',$greets1,$result);
preg_match('/(hello)((?(?=\\\ jack)j))/',$greets1,$result);
これらのどれも機能しませんでした。