Regex question

Doug Miles doug.miles at
Fri Feb 2 14:07:22 CST 2001

This is probably something obvious, but I don't have my regex book with
me, and can't seem to figure it out.  I'm trying to parse space
delimited information, somewhat like the UNIX command line.  Whitespace
delimits parameters, but parameters can containg whitespace if
surrounded by quotes.  Here's the code:


my $string = qq(DailyNAV "Class C" nav);

my @tokens = $string =~ /(\S+)/g;
print join('|', @tokens) . "\n";
my @tokens = $string =~ /"([^"]+)"/g;
print join('|', @tokens) . "\n";
my @tokens = $string =~ /"([^"]+)"|(\S+)/g;
print join('|', @tokens) . "\n";

here is the output:

Class C
|DailyNAV|Class C|||nav

The first two regexes do what I expect.  When I combine them in the
third, I get extra "null matches".  Any ideas as to what I'm doing

- Doug

Encrypted with ROT-26 - all attempts to decrypt are illegal under the

More information about the Phoenix-pm mailing list