Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Zero-width assertions fail with split

by merlyn (Sage)
on Sep 19, 2005 at 05:00 UTC ( [id://493079]=note: print w/replies, xml ) Need Help??


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); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://493079]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found