我正在尝试检查“;”也在if循环中,但如果我包含“;”要么 ”\;”它不起作用..不知道我在这里做错了什么..
# Check "!", "[]" and "#"
while ( <$fh> ) {
if ( m/^(?:[!\[]|#\s)/ ) {
output $current, $fhout;
$current = [ $_ ];
}
else {
push @$current, $_;
}
}
答案 0 :(得分:3)
不需要非捕获括号,/^[!#;]|^\[]/
应该没问题:
perl -Mstrict -wE "do{ say $_, ' matches' if /^[!#;]|^\[]/} for qw/ ;23 25df fg43 !sdf [56y ]][s #faw []13 /;"
Possible attempt to put comments in qw() list at -e line 1. ;23 matches !sdf matches #faw matches []13 matches