How do you put comments inside a Perl regular expression?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use the /x modifier:
my $foo = "zombies are the bombies";
if ($foo =~ /
zombie # sorry pirates
/x ) {
print "urg. brains.\n";
}
Also see the first question in perlfaq6.
Also it wouldn't hurt to read all of perlre while you're at it.
回答2:
Even without the /x modifier, you can enclose comments in (?# ... ):
my $foo = "zombies are the bombies";
if ( $foo =~ /zombie(?# sorry pirates)/ ) {
print "urg. brains.\n";
}