【发布时间】:2014-04-16 01:35:39
【问题描述】:
我对 Perl 前瞻 (?=regex) 和后瞻 (?<=regex) 感到困惑,需要一些帮助来理解它。
前瞻是指look to the right of (?=regex)
lookbehind 的意思是look to the left of (?<=regex)
我还注意到lookbehind (?
例如,给出以下代码行,我想匹配数字,但前提是它不在注释行中。所以它应该匹配2,而不是1
#Comment 1
my $number = 2
我试过了
/(?<!^#)\d/
match a number if the line does not start with #
那没有用,是因为它不是一个固定宽度的lookbehind正则表达式吗?
谢谢
【问题讨论】:
-
你要解析什么语言?
-
我只是在自学一些 Perl 正则表达式,仅以该代码为例。
-
我明白,但没有上下文和规则,你的问题没有任何意义。
-
嗯,我相信我的问题非常具体和明确。
-
"mmmmmm" : "例如,给出以下代码行,"。什么样的代码?