相关疑难解决方法(0)

有没有更好的方法用/ x编写Perl正则表达式,所以代码仍然易于阅读?

我在我的一个脚本上运行了Perl :: Critic,并收到了以下消息:

Regular expression without "/x" flag at line 21, column 26. See page 236 of PBP.
Run Code Online (Sandbox Code Playgroud)

在这里查看了策略信息,并且我理解在扩展模式下编写正则表达式将有助于任何正在查看代码的人.

但是,我被困在如何转换我的代码以使用/ x标志.

CPAN示例:

# Match a single-quoted string efficiently...

m{'[^\\']*(?:\\.[^\\']*)*'};  #Huh?

# Same thing with extended format...

m{
    '           # an opening single quote
    [^\\']      # any non-special chars (i.e. not backslash or single quote)
    (?:         # then all of...
        \\ .    #    any explicitly backslashed char
        [^\\']* #    followed by an non-special chars
    )*          # ...repeated zero or …
Run Code Online (Sandbox Code Playgroud)

regex perl perl-critic

8
推荐指数
4
解决办法
5638
查看次数

标签 统计

perl ×1

perl-critic ×1

regex ×1