in reply to Re: Re: Not quite a simple split
in thread Not quite a simple split

The regex could be changed to:
@parts = $string =~ m{ ( (?: [^\s"]+ # one or more non-quote/whitespace | " [^"]* " # a quoted part )+ # one or more times ) }xg;
This probably runs better.
_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Re: Re: Not quite a simple split
by John M. Dlugosz (Monsignor) on Feb 02, 2004 at 16:25 UTC
    Why don't you need the (?=\S) in this version? Because it doesn't match an empty string (in the first one, either part was optional which made both parts optional at the same time)?
      Absolutely correct (on both accounts).
      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
Re^4: Not quite a simple split
by Roy Johnson (Monsignor) on Feb 02, 2004 at 19:52 UTC
    Your code counts 8"foo"8 as one token, but I think the token is supposed to terminate after the 2nd quote, leaving the second 8 as a separate token.
    m/([^\s"]+|[^\s"]*(?:"[^"]*"))/g

    The PerlMonk tr/// Advocate