my $regex = qr/ \A [^,]+ \Z /x;
...
my $flag = 1 if $var =~ /\G ($regex) /gcx;
Because qr/ \A [^,]+ \Z /x matches an entire string, the /g regex modifier has no meaning (and it's also used in a boolean context). Likewise the /c modifier. Likewise the \G anchor. Likewise the capture group around the $regex regex object, although in the original code a capture may be pertinent.
>perl -wMstrict -le "my $rx = qr/ \A [^,]* \z /x; ;; for my $s (',abcd', 'abc,d', 'abcd,', ',,,', 'abcd', '.;$%&', '') { print qq{'$s' }, $s =~ $rx ? '' : 'NO', ' match'; } " ',abcd' NO match 'abc,d' NO match 'abcd,' NO match ',,,' NO match 'abcd' match '.;$%&' match '' match
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: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |