Possible Duplicate:
A Regex that will never be matched by anything
I have a script that takes a regex as a parameter. By default I want to set the regex to something that will never match any string, so I can simply say
if ($str =~ $regex)
without e.g. having to check defined($regex) first.
I came up with
qr/[^\s\S]/
but don't know if this will match some utf8 character that is neither a space nor a non-space.
/(?!)/
http://perl.plover.com/yak/regex/samples/slide049.html
Combine a negative lookahead for an arbitrary character followed by a match for that character, e.g.
/(?!x)x/
Works on all the test cases I threw at it. Here are some tests on rubular.
/ ^/
seems to do, and is short(est).
精彩评论