in reply to Re: Look Behind not work, please help
in thread Look Behind not work, please help

That's an interesting technique.

The split() call normally captures everything that doesn't match the regex; in this case, it's the unquoted parts. You add on a capture in the regex, which tells split to also keep the separators; in this case, it's the quoted parts. The non-obvious part is that split will interleave the captures-in-separators and the usual non-separator portions properly.

--
[ e d @ h a l l e y . c c ]

  • Comment on Re: Re: Look Behind not work, please help

Replies are listed 'Best First'.
Re: Re: Re: Look Behind not work, please help
by jmcnamara (Monsignor) on Apr 30, 2003 at 15:32 UTC

    Yes, it is one of the many interesting features of split, from the pod:
    If the PATTERN contains parentheses, additional list elements are created from each matching substring in the delimiter. split(/([,-])/, "1-10,20", 3); produces the list value (1, '-', 10, ',', 20)

    Other interesting features of split are LIMIT, negative LIMIT, the parameter-less split, the difference between ' ', / / and /\s+/ and the implicit split to @_ when not in a list context (which is very useful in Golf).

    I used one of these features in Strip leading and trailing whitespace from a string..

    --
    John.