你如何评论Perl正则表达式?

时间:2021-10-21 19:25:31

How do you put comments inside a Perl regular expression?

你如何在Perl正则表达式中放置注释?

2 个解决方案

#1


22  

Use the /x modifier:

使用/ x修饰符:

my $foo = "zombies are the bombies";
if ($foo =~ /
             zombie  # sorry pirates
            /x ) {
    print "urg. brains.\n";
}

Also see the first question in perlfaq6.

另请参阅perlfaq6中的第一个问题。

Also it wouldn't hurt to read all of perlre while you're at it.

当你在它的时候阅读所有的perlre也不会有什么坏处。

#2


18  

Even without the /x modifier, you can enclose comments in (?# ... ):

即使没有/ x修饰符,也可以将注释括在(?#...)中:

my $foo = "zombies are the bombies";
if ( $foo =~ /zombie(?# sorry pirates)/ ) {
    print "urg. brains.\n";
}

#1


22  

Use the /x modifier:

使用/ x修饰符:

my $foo = "zombies are the bombies";
if ($foo =~ /
             zombie  # sorry pirates
            /x ) {
    print "urg. brains.\n";
}

Also see the first question in perlfaq6.

另请参阅perlfaq6中的第一个问题。

Also it wouldn't hurt to read all of perlre while you're at it.

当你在它的时候阅读所有的perlre也不会有什么坏处。

#2


18  

Even without the /x modifier, you can enclose comments in (?# ... ):

即使没有/ x修饰符,也可以将注释括在(?#...)中:

my $foo = "zombies are the bombies";
if ( $foo =~ /zombie(?# sorry pirates)/ ) {
    print "urg. brains.\n";
}