Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Supress similar chars in the string

by Anonyrnous Monk (Hermit)
on Jan 18, 2011 at 17:44 UTC ( [id://882934]=note: print w/replies, xml ) Need Help??


in reply to Re: Supress similar chars in the string
in thread Supress similar chars in the string

Newer Perls (>=5.10) also allow you to say

s/(.)\1\1\K\1*//g;

i.e., through the use of \K, you don't need to copy the part of the match you want to keep ($1 in your regex) into the substitution.

Replies are listed 'Best First'.
Re^3: Supress similar chars in the string
by AnomalousMonk (Archbishop) on Jan 18, 2011 at 22:36 UTC
    s/(.)\1\1\K\1*//g;

    Shouldn't  \1* in regex above be  \1+ for reason similar to that discussed in Re^3: Supress similar chars in the string: useless replacement of empty string with empty string? (Or is regex engine smart enough to avoid this null operation?)

Log In?
Username:
Password:

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

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

    No recent polls found