in reply to Zero-width assertions fail with split

De Morgan is kicking your hiney.

It's working as I would expect. You are asking to split on commas that have neither dashes before NOR dashes afterwards, as in "the delimiter is NOT dashes ahead AND a comma AND NOT dashes afterwards". That's the only time the split regex would match. Dashes on either side would prevent the comma from being considered. Your experimental results are borne out.

And simply splitting on commas would give you the list you want, so you'll have to show an example where simply splitting on commas doesn't do it.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on Re: Zero-width assertions fail with split

Replies are listed 'Best First'.
Re^2: Zero-width assertions fail with split
by Ovid (Cardinal) on Sep 19, 2005 at 05:06 UTC

    That makes sense and, as noted, the results aren't entirely suprising, though I confess I struggled with it. Is there some simple way of getting the split behavior to do what I want?

    Cheers,
    Ovid

    New address of my CGI Course.

      You want "not both preceded and followed by TOKEN", which is equivalent to "either not preceded by TOKEN, or not followed by TOKEN", and that we can do:

      my $split = qr/ (?<!$token) , | , (?!$token) /x;

      Hugo

      Hi,

      It may be silly, but, doesn't this do what you want?

      perl -e '$a = "1,2,---0---,3,4";@f=split ",",$a;map { print $_."\n"} @f'
      --
      if ( 1 ) { $postman->ring() for (1..2); }