Trouble adding ';' in Perl regex
I'm trying to check for ";" also in the if loop, but If I include ";" or "\;" it doesn't work.. Not sure what I'm doi开发者_如何转开发ng wrong here..
# Check "!", "[]" and "#"
while ( <$fh> ) {
if ( m/^(?:[!\[]|#\s)/ ) {
output $current, $fhout;
$current = [ $_ ];
}
else {
push @$current, $_;
}
}
No need for the non-capturing parentheses, /^[!#;]|^\[]/
should be fine:
perl -Mstrict -wE "do{ say $_, ' matches' if /^[!#;]|^\[]/} for qw/ ;23 25df fg43 !sdf [56y ]][s #faw []13 /;"
Output
Possible attempt to put comments in qw() list at -e line 1. ;23 matches !sdf matches #faw matches []13 matches
精彩评论