in reply to Re^2: Regex to capture every readable character except COMMA
in thread Regex to capture every readable character except COMMA
Good points! So maybe a regex like this, using a positive lookahead, would be more useful here:
use strict; use warnings; my $regex = qr/ ([^,]+) (?=\Z|,) /x; my $var = 'abcd,ef,,ghijkl,mnop'; print "$1\n" while $var =~ /$regex/g;
Output:
18:27 >perl 827_SoPW.pl abcd ef ghijkl mnop 18:27 >
But then, the same result can be obtained by discarding the regex and using split instead:
use strict; use warnings; my $var = 'abcd,ef,,ghijkl,mnop'; my @matches = split /,/, $var; $_ && print "$_\n" for @matches;
;-)
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regex to capture every readable character except COMMA
by AnomalousMonk (Archbishop) on Jan 09, 2014 at 18:27 UTC |