小编Eri*_*sen的帖子

我必须在Perl预编译的正则表达式中逃避哪些字符?

在使用Perl的qr {}构造时,我很难确定必须转义哪些字符

我正在尝试为包含大量正常转义字符(#*.>:[])的文本创建多行预编译正则表达式,并且还包含另一个预编译的正则表达式.另外,我需要尽可能严格地进行匹配以进行测试.

my $output = q{# using defaults found in .config
*
*
Options:
  1. opt1
> 2. opt2
choice[1-2?]: };

my $sc = qr{(>|\s)}smx;
my $re = qr{# using defaults found in .config
*
*
Options:
$sc 1. opt1
$sc 2. opt2
choice[1-2?]: }mx;

if ( $output =~ $re ) {
  print "OK!\n";
}
else {
  print "D'oh!\n";
}
Run Code Online (Sandbox Code Playgroud)

错误:

Quantifier follows nothing in regex; marked by <-- HERE in m/# using defaults found in .config …
Run Code Online (Sandbox Code Playgroud)

regex perl multiline qr-operator

5
推荐指数
2
解决办法
7101
查看次数

标签 统计

multiline ×1

perl ×1

qr-operator ×1

regex ×1