if($var =~ /,/) { print "not matches \n"; } elsif($var =~ /(.*)/) { print "matches \n Captured: $1\n"; }
The intent here seems to be to capture the entire string if it contains no comma. But $var already holds the entire string! Why 'capture' it again?
Furthermore, a confounding subtlety lurks at the heart of the seemingly simple, innocent /(.*)/ regex: the . (dot) metaoperator matches everything except a newline: it will only capture up to the first newline, if present. You have just built a bug into your code. (This subtlety is the rationale for the PBP injunction to always use the /s "dot matches all" modifier with every regex.)
In reply to Re^2: Regex to capture every readable character except COMMA
by AnomalousMonk
in thread Regex to capture every readable character except COMMA
by nehavin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |