On Dec 12, Pete Emerson said:
>I'm intrigued by Jon Molin's response, though:
>> my @ar = ($a =~ /((?:\"[^\"]*\"|[^\s]*))\s?/g); #should be possible to remove "
The (?: ... ) isn't even NEEDED in this regex, though.
((?:X|Y))
can be written as
(X|Y)
>> s/\"//g foreach (@ar);
The " is not a regex metacharacter, and does not need backslashing here
nor above.
>> print "$_\n" foreach (@ar);
>
>This works, too, but I don't understand what the ?: is for;
>my Perl book says it doesn't do backreferences; what does that mean?
A back-reference is thus:
($chunk) = "broadway" =~ /((.).*\2)/;
\2 refers to the second opening parenthesis and its matching closing
parenthesis. The regex itself matches some character, then any number of
characters, and then that FIRST character again. \2 is a back-reference.
For the task of parsing quoted strings, my book suggests the inchworm
method:
push @terms, $1 while
/\G\s*"([^"]*)"/g or
/\G\s*(\S+)/g;
That breaks your problem down into two smaller ones.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]