Why in perl this regex is not matching line
我对perl代码进行了一些更改,但我不明白为什么下面的正则表达式与输入行不匹配。
1 2 3 4 5 6 | my $regex='^(780200703303)\\\\s+(\\\\d+)\\\\s+(\\\\d+)\\\\s+(\\\\d+)\\\\s+(\\\\d+)\\\\s+(\\\\d+)\\\\s+(\\\\d+)\\\\s+(\\\\d+)\\\\s+(\\\\d+)\\\\s+([1-9]\\\\d*)\\\\s+([1-9]\\\\d*)\\\\s+$'; my $line='780200703303 2 0 3 0 0 0 0 0 0 1 '; if ( $line =~ m/$regex/ ) { print"Matched"; } |
在此先感谢
因为
您是否考虑过使用以下内容:
1 2 3 4 |
您的测试字符串与正则表达式不匹配。
1 2 | my $regex='\\\\s+([1-9]\\\\d*)\\\\s+([1-9]\\\\d*)\\\\s+$'; my $line=' 0 1 '; |
不匹配
通过使用
1 | my $regex= qr/\\s+([1-9]\\d*)\\s+([1-9]\\d*)\\s+$/; |