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

Re: removing duplicate letters

by plaid (Chaplain)
on Jun 18, 2000 at 23:50 UTC ( #18728=note: print w/replies, xml ) Need Help??


in reply to removing duplicate letters

This seems to work:
s/(.)\1/$1/g;
The tr operator does what you want, except it squashes all duplicates, not just two. For reference though:
tr/a-zA-Z//s;

Replies are listed 'Best First'.
RE: Re: removing duplicate letters
by Ovid (Cardinal) on Jun 19, 2000 at 00:50 UTC
    Actually, the dot operator doesn't fit his definition. eduardo specified letters so we should change it to
    s/(\w)(\1)/$1/g;
    Update: Oops! takshaka exposed me for the fake I am! (see reply below)
      If we're going to be pedantic, \w matches nonletters as well. Use a character class with the appropriate definition of "letters".

      s/([a-zA-Z])\1/$1/g;

        if you want to talk about pedantic, your letters may not be the letters everyone else is using, so to take the locale into effect, you could do something like the following:

        s/([^\W\d_])\1/$1/g
RE: Re: removing duplicate letters
by eduardo (Curate) on Jun 19, 2000 at 00:01 UTC
    damn it ;) that's it, that's what i wanted...
    s/(.)\1/$1/g;
    oh well, what i kept on trying was:
    s/(.)\$1/$1/g;
    and that sure as hell didn't work ;) thank you very much!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-01-20 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (56 votes). Check out past polls.

    Notices?