On Jun 7, Accountant Bob said:
>can any one explain to me why this doesn't seem to work:
> push @elements, $2 while
> /\G\s*(["'])([^\\\1]*(?:\\.[^\\\1]*)*)\1/gc or
> /\G(\s*)(\S+)/gc; # k i know that's kinda kloogy, but I'm
>experimenting.
Let's find out why:
friday:~ $ explain
\G\s*(["'])([^\\\1]*(?:\\.[^\\\1]*)*)\1
[snip]
----------------------------------------------------------------------
[^\\\1]* any character except: '\\', '\1' (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
[snip]
As you see, putting \1 in a character class matches the character
"\1". That's not what we wanted; but character classes must be known at
the regex's compile-time.
You could do:
push @matches, $+ while
/\G\s*(["'])((??{"[^$1\\\\]*")(?:\\.(??{"[^$1\\\\]*"))*)/gc or
/\G\s*(\S+)/gc;
But that is ugly, and requires Perl 5.6.0+.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **