Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Remove duplicate from the same line.

by Athanasius (Archbishop)
on Jun 01, 2013 at 15:05 UTC ( #1036452=note: print w/replies, xml ) Need Help??

in reply to Remove duplicate from the same line..

The following regex will remove any word or phrase that duplicates its immediate predecessor:

$string =~ s/ \b (.+) \b \s* \1 /$1/gx;

But note that an address such as “Long Island City, NY NY” will be reduced to “Long Island City, NY”.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Remove duplicate from the same line.
by Anonymous Monk on Jun 01, 2013 at 17:30 UTC
    Thx. Athanasius. but I have some more doubts, pls can you check the reply I gave to rpnoble

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-04-14 02:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found