Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Elegant way to split into sequences of identical chars?

by tphyahoo (Vicar)
on Dec 05, 2005 at 09:50 UTC ( #514077=note: print w/replies, xml ) Need Help??


in reply to Re: Elegant way to split into sequences of identical chars?
in thread Elegant way to split into sequences of identical chars?

A little less obfuscated if you use extended regex comments. (I liked this solution a lot, because I feel like it gets to the "core" of what is wanted.)

use strict; use warnings; use Data::Dumper; print join " ", splitter('xx((556xx'); sub splitter { local $_ = shift; split / (?<!^) #not preceeded by + start of string. (?! #not followed by... (??{ quotemeta substr($_, $-[0]-1, 1) # the escaped +(quote-metad) last character of the last match. # note: $-[0] is th +e offset of start of last successful match. # $-[1] (not used h +ere) would be the offset of start of the first sub pattern. }) ) /x; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2019-05-23 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (146 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!