Re: fun with regex/split

2001-12-13 Thread Andrea Holstein
Pete Emerson wrote: > > I'd appreciate it if someone could help me wrap my brain around this one. > I've got a string like this: > $string='"one two" three "four five six"'; > > I'd like to wind up with an array like this: > one two > three > four five six > > Essentially, I would like to split

Re: fun with regex/split

2001-12-13 Thread Jenda Krynicky
From: Pete Emerson <[EMAIL PROTECTED]> > I'd appreciate it if someone could help me wrap my brain around this > one. I've got a string like this: $string='"one two" three "four five > six"'; > > I'd like to wind up with an array like this: > one two > three > four five six > >

Re: fun with regex/split

2001-12-12 Thread Jeff 'japhy' Pinyan
On Dec 12, Pete Emerson said: >Jeff 'japhy' Pinyan wrote: > >> 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; > >Hmmm...mine seems to go into an infinite loop: Oops. That'll teach m

Re: fun with regex/split

2001-12-12 Thread Pete Emerson
Jeff 'japhy' Pinyan wrote: > 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; Hmmm...mine seems to go into an infinite loop: #!/usr/bin/perl -w use strict; my @terms; $_='"one two three"

Re: fun with regex/split

2001-12-12 Thread Jeff 'japhy' Pinyan
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 no

Re: fun with regex/split

2001-12-12 Thread Etienne Marcotte
I don't know about regexes, Jeff Pinyan is the master and can probably give you the right answer. But for me I can't understand the regex he made, and if your code will be read by someone else, I suggest the split for clarity and for speed (well this would need to be benchmarked but I'm sure it's

Re: fun with regex/split

2001-12-12 Thread Pete Emerson
Thank you all for your quick responses. Splitting on the " was the key. I'm intrigued by Jon Molin's response, though: > my @ar = ($a =~ /((?:\"[^\"]*\"|[^\s]*))\s?/g); #should be possible to remove " > s/\"//g foreach (@ar); > print "$_\n" foreach (@ar); This works, too, but I don't understand w

Re: fun with regex/split

2001-12-12 Thread Jon Molin
i bet there's way of doing this on one line: my $a = '"one two" three "four five six" seven eight nine'; my @ar = ($a =~ /((?:\"[^\"]*\"|[^\s]*))\s?/g); #should be possible to remove " s/\"//g foreach (@ar); print "$_\n" foreach (@ar); /Jon Pete Emerson wrote: > > I'd appreciate it if someo

Re: fun with regex/split

2001-12-12 Thread Etienne Marcotte
why don't you split on /"/ ? then regex to remove the leading and trailing spaces. Etienne Pete Emerson wrote: > > I'd appreciate it if someone could help me wrap my brain around this one. > I've got a string like this: > $string='"one two" three "four five six"'; > > I'd like to wind up with

fun with regex/split

2001-12-12 Thread Pete Emerson
I'd appreciate it if someone could help me wrap my brain around this one. I've got a string like this: $string='"one two" three "four five six"'; I'd like to wind up with an array like this: one two three four five six Essentially, I would like to split up the string on spaces, but ignore spaces