开发者

Trouble adding ';' in Perl regex

开发者 https://www.devze.com 2023-03-31 03:33 出处:网络
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..

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
0

精彩评论

暂无评论...
验证码 换一张
取 消