我在使用Jeffrey Friedl的着作Mastering Regular Expressions 3rd Ed的"负面外观"代码运行我的perl脚本时遇到以下错误.(第167页).任何人都可以帮我吗?
错误消息:
序列(?在正则表达式中不完整;用< - HERE标记m /((?< - HERE/at /home/wubin28/mastering_regex_cn/p167.pl第13行.
我的perl脚本
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
my $str = "<B>Billions and <B>Zillions</B> of suns";
if ($str =~ m!
(
<B>
(
(?!<B>) ## line 13
.
)*?
</B>
)
!x
) {
print "\$1: $1\n"; #output: <B>Billions and <B>Zillions</B>
} else {
print "not matched.\n";
}
Run Code Online (Sandbox Code Playgroud)
你使用符号的错误!用于打开和关闭正则表达式,同时使用负向前瞻(?!.).如果您更改打开和关闭符号{和},或//.你的regexp评估很好.
use strict;
my $str = "<B>Billions and <B>Zillions</B> of suns";
if ($str =~ m/(<B>((?!<B>).)*?<\/B>)/x) {
print "\$1: $1\n"; #output: <B>Billions and <B>Zillions</B>
} else {
print "not matched.\n";
}
Run Code Online (Sandbox Code Playgroud)