Thread Regex negieren
(27 answers)
Opened by fs at 2010-03-19 09:57 2010-03-19T09:46:50 fs Man sollte Benutzereingaben nicht einfach als Regex ausführen. Vor allem, wenn es keine vertrauenswürdigen Benutzereingaben sind. Zum Thema: Code (perl): (dl
)
1 2 3 4 5 my @strings = qw(blah blubb hallo welt hallohallohallo hallihallo); my $re = qr{^(?!hallo\z)}; print "$_\n" for grep /$re/, @strings; Gibt alle Strings ausser "hallo" aus. Edit: Und das folgende gibt alle Strings aus, in denen nicht "hallo" vorkommt: Code (perl): (dl
)
1 2 3 4 5 my @strings = qw(blah blubb hallo welt hallohallohallo hallihallo); my $re = qr{^(?:(?!hallo).)*\z}s; print "$_\n" for grep /$re/, @strings; Last edited: 2010-03-19 14:43:36 +0100 (CET) Lieblingsmodule:
![]() ![]() |