On Jun 7, Ondrej Par said:
>On Wednesday 06 June 2001 22:59, Jeff 'japhy' Pinyan wrote:
>> On Jun 6, Accountant Bob said:
>> >How about this: (the same but "unrolled")
>> >
>> >my @elements;
>> >push @elements, $1 while
>> > /\G\s*"([^\\"]*(?:\\["\\][^\\"]*)*)"/gc or
>
>I think that
> /\G\s*"((?:(?:\\.)|[^\\])*?)"/gc
>
>is shorter and also matches all \X sequences (the trick is that \\. is longer
>than [^\\]
The formula for unrolling the loop is
NORMAL* (SPECIAL NORMAL*)*
Here, NORMAL is /[^\\"]/, and SPECIAL is /\\./ -- at least, I'm using \\.,
since I want any backslash to pass through ok.
Thus, our regex is:
push @elements, $1 while
/\G\s*"([^\\"]*(?:\\.[^\\"]*)*)"/gc or
/\G\s*'([^\\']*(?:\\.[^\\']*)*)'/gc or
/\G\s*(\S+)/gc;
Of course, that last regex can changed to your whims...
--
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 **