Following on from davido’s answer: if you want to match only when the string contains no commas, you have to specify that every character is a non-comma; therefore, you need to anchor the regex at the start and end of the string. For example:
#! perl use strict; use warnings; my $regex = qr/ \A [^,]+ \Z /x; my $var = "abc,d"; my $flag = 1 if $var =~ /\G ($regex) /gcx; print $flag ? '' : 'not ', "matches\n";
Output:
16:38 >perl 827_SoPW.pl not matches 16:42 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Regex to capture every readable character except COMMA
by Athanasius
in thread Regex to capture every readable character except COMMA
by nehavin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |