in reply to Re: Not quite a simple split
in thread Not quite a simple split
So, let me understand... the first thing, (?=\S) will fail if the next character is whitespace or there is no next character. I wonder why we need that? Ah, it interacts with the /g to say "no match at this postion" to actually skip the spaces! And the spaces naturally don't wind up in the returned array. Beautiful.
I also like the way the non-quote stuff is always first, and the quoted part is an optional part that follows, rather than having two totally different cases.
So first it matches everything that's not whitespace or a quote.
Then it picks up the quote, stuff inside it, and close quote. Then it has [^\s"]* again, and the whole thing is in a repeat star. That means it will handle anything with an even number of quotes in it, not just a single pair and end on the close-quote.
That is an interesting generalization, and I rather like it.
I suppose you couldn't pull the non-quote non-whitespace part out of the loop because it must be performed at least once. Ah, but you know it's not a space already, and taking out the 3rd line and changing the 7th line from * to + would work, and further allow things that begin with a quote. Would it not?
—John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Not quite a simple split
by japhy (Canon) on Feb 02, 2004 at 14:15 UTC | |
by John M. Dlugosz (Monsignor) on Feb 02, 2004 at 16:25 UTC | |
by japhy (Canon) on Feb 02, 2004 at 19:16 UTC | |
by Roy Johnson (Monsignor) on Feb 02, 2004 at 19:52 UTC |