in reply to Regex to capture every readable character except COMMA
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to capture every readable character except COMMA
by AnomalousMonk (Archbishop) on Jan 09, 2014 at 07:19 UTC | |
by Athanasius (Archbishop) on Jan 09, 2014 at 08:36 UTC | |
by AnomalousMonk (Archbishop) on Jan 09, 2014 at 18:27 UTC |