Unterschied RegEx Flag "m" zu "s"
Andreas Korthaus
- sonstiges
Hallo!
Ich verstehe irgendwie den Unterschied zw. dem Flag "m" und "s" eines regulären Ausdrucks nicht wirklich.
unter http://selfhtml.teamone.de/cgiperl/sprache/regexpr.htm#flags steht dazu:
m Zeichenketten können aus mehreren Zeilen bestehen
s Zeichenketten als eine einzige Zeile betrachten
Was genau ist da bitte der Unterschied? Können Zeichenketten nicht grundsätzlich aus mehreren Zeilen bestehen? Wozu dann das flag "m"?
Viele Grüße
Andreas
Hi,
Ich verstehe irgendwie den Unterschied zw. dem Flag "m" und "s" eines regulären Ausdrucks nicht wirklich.
unter http://selfhtml.teamone.de/cgiperl/sprache/regexpr.htm#flags steht dazu:
m Zeichenketten können aus mehreren Zeilen bestehen
s Zeichenketten als eine einzige Zeile betrachten
Was genau ist da bitte der Unterschied? Können Zeichenketten nicht grundsätzlich aus mehreren Zeilen bestehen? Wozu dann das flag "m"?
perldoc perlre sagt dazu:
m Treat string as multiple lines. That is, change "^" and "$" from
matching the start or end of the string to matching the start or end
of any line anywhere within the string.
s Treat string as single line. That is, change "." to match any
character whatsoever, even a newline, which normally it would not
match.
The "/s" and "/m" modifiers both override the $* setting. That is,
no matter what $* contains, "/s" without "/m" will force "^" to
match only at the beginning of the string and "$" to match only at
the end (or just before a newline at the end) of the string.
Together, as /ms, they let the "." match any character whatsoever,
while still allowing "^" and "$" to match, respectively, just after
and just before newlines within the string.
cu,
Andreas
Hi!
The "/s" and "/m" modifiers both override the $* setting. That is,
no matter what $* contains, "/s" without "/m" will force "^" to
match only at the beginning of the string and "$" to match only at
the end (or just before a newline at the end) of the string.
Together, as /ms, they let the "." match any character whatsoever,
while still allowing "^" and "$" to match, respectively, just after
and just before newlines within the string.
Danke Euch!
Verstehe ich das jetzt richtig dass der Unterschid zu keinem flag und /m darin besteht das ^ und $ nicht nur auf String-Anfang bzw. -Ende treffen, sondern von bzw. nach jedem newline?
/s im gegensatz zu ohne flag triff t mit . auch newline-Zeichen, und in Kombination treffen /ms treffen . auf alle Zeichen(auch newline) aber ^ und $ funktionieren trotzdem wie bei /m alleine. Ist das so richtig?
Grüße
Andreas
Hallo,
In meinem schlauen Perl Büchlein steht folgendes. Vielleicht hilft dir das :
m : verwendet ^ und $ für Neue Zeile
s : schließt die Neue-Zeile-Zeichen mit ein
$xNeTworKx.