Ich versuchte, das PHP-Handbuch PCRE regex syntax->AssertionsPHP Regex Negative Assertions Erklärung
Es gibt eine Beschreibung wie folgt zu verstehen: foo(?!bar) matches any occurrence of "foo" that is NOT followed by "bar".
Während ich die Probe mit folgendem Ergebnis versucht:
$text = "foobar foobar foobar fooabar";
$rules = "/foo(!?bar)/is";
preg_match_all($rules, $text, $matches);
$newLine = preg_replace($rules, "\thahaha", $text);
print_r($matches);
echo "<br/>";
echo $rules. ":" .$newLine;
// result
Array ([0] => Array ([0] => foobar [1] => foobar [2] => foobar) [1] => Array ([0] => bar [1] => bar [2] => bar))
/foo(!?bar)/is: hahaha hahaha hahaha fooabar
Alle Vorkommen von "foo" mit "bar" wird ersetzt. Also, ist es eigentlich die gegenteilige Bedeutung? Oder habe ich etwas woanders vermisst? foo(?!bar) matches any occurrence of "foo" that is followed by "bar"???
Vielen Dank im Voraus.
Es sollte "foo (?! Bar)" und nicht "foo (!? Bar)" sein. – Rahul
Danke für Ihre Erklärung, ich sollte das nächste Mal genauer in die Details schauen. :) @Rahul – simongcc