[英]Error in Perl: Nested quantifiers in regex
Im a Perl noob and I have been trying to develop a simple script to capture some values from a regex. 我是Perl新手,我一直在尝试开发一个简单的脚本来捕获正则表达式中的某些值。 So far I have built the following program: 到目前为止,我已经构建了以下程序:
#!/usr/bin/perl
use strict;
$/ = '';
my $PM = qr{\b[A-Z][\w-]*\w};
my $de = qr{d[aoe]s?};
my $s = qr{[\n ]};
my $np = qr{$PM (?: $s $PM | $s $de $s $PM )*}x;
my $window_size = 7;
my $window = qr{($np) (?: $s+ (\w+))*};
while(<>){
while(/($np) (?: $s+ (?: [\w-]+ | ($np))) ** {0..$window_size} /xg){
print("\$1: $1 and \$2: $2 \n");
}
}
However, when I try to run this code, it shows me the following error: 但是,当我尝试运行此代码时,它显示了以下错误:
Nested quantifiers in regex; marked by <-- HERE in m/((?^ux:(?^u:\b[A-Z][\w-]*\w) (?: (?^u:[\n ]) (?^u:\b[A-Z][\w-]*\w) | (?^u:[\n ]) (?^u:d[aoe]s?) (?^u:[\n ]) (?^u:\b[A-Z][\w-]*\w) )*)) (?: (?^u:[\n ])+ (?: [\w-]+ | ((?^ux:(?^u:\b[A-Z][\w-]*\w) (?: (?^u:[\n ]) (?^u:\b[A-Z][\w-]*\w) | (?^u:[\n ]) (?^u:d[aoe]s?) (?^u:[\n ]) (?^u:\b[A-Z][\w-]*\w) )*)))) ** <-- HERE {0..7} / at ./main.pl line 22, <> chunk 1.
Why is this not working? 为什么这不起作用?
EDIT: Im trying to use the **
operator as the general quantifier, followed by a range. 编辑:我试图使用**
运算符作为一般量词,然后是一个范围。 I have read that it is equivalent to {range min, range max} quantifier 我已经读过它相当于{range min,range max}量词
如果您不匹配带有“ **”的文字字符串,则需要对其进行转义。
/($np) (?: $s+ (?: [\w-]+ | ($np))) \*\* {0..$window_size} /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.