Christian Seiler: Ähnliche Frage - Look(ahead|behind) Assertations

Beitrag lesen

Hallo Mathias,

BTW, kannst du mir ein Beispiel für den Unterschied zwischen ^und \A und $ und \Z geben (wenn der i pattern modifier gesetzt ist) - mir war nämlich bisher nur ^ und $ bekannt.

i-Modifier = case-insensitive; was hat das denn damit zu tun?

Es gibt nur einen Unterschied mit dem m-Modifier.

$string = "hallo
ciao";

preg_match("/\Ahallo\Z/m", $string) => false
preg_match("/\Aciao\Z/m", $string) => false
preg_match("/^hallo$/m", $string) => true
preg_match("/^ciao$/m", $string) => true
preg_match("/\Ahallo\nciao\Z/m", $string) => true
preg_match("/^hallo\nciao$/m", $string) => false
-----
preg_match("/\Ahallo\nciao\Z/m", $string) => true
preg_match("/^hallo\nciao$/m", $string) => true
preg_match("/\Ahallo\Z/m", $string) => false
preg_match("/\Aciao\Z/m", $string) => false
preg_match("/^hallo$/m", $string) => false
preg_match("/^ciao$/m", $string) => false

Alles klar?

Grüße,

Christian