in reply to Not quite a simple split

There's a FAQ entry (no, not on this site, but there is Perl life outside of it, too, you know :): How can I split a [character] delimited string except when inside [character]? (Comma-separated files)

Anyway, aside from that, my first though would be along these lines:

@tokens = /(?:".*?"|\S)+/g;
which, with the string
$_ = 'Here we have u"a quoted string" and a .';
produces, with each item of @tokens on a separate line:
Here
we
have
u"a quoted string"
and
a
.
Looks fine to me.

Replies are listed 'Best First'.
Re: Re: Not quite a simple split
by John M. Dlugosz (Monsignor) on Feb 02, 2004 at 03:33 UTC
    You and BrowserUK had what I almost came up with the other night. When switching from split to re/g, I was missing the part about it scanning to the next match, skipping stuff that doesn't match (spaces).

    Hmm, but that means it will silently skip syntax errors, too! I wonder...