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 Essentially, I

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 up the string

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

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 someone could

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 what the ?:

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

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 not a regex

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 four five

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 me not to copy out