in reply to most efficient regex to delete duplicate words
the second line does something that may not be obvious to everyone, and seems to duplicate /g 's functionality. However, since you've (seemingly) got 3 gamma in a row, writing$_="alpha beta beta gamma gamma gamma"; while (s/((\w+)\s\2)/$2/) {}; print $_;
Will leave you with an extra gamma. Using the 'useless' while loop allows the regex to check for multiple duplicates.$_="alpha beta beta gamma gamma gamma"; s/((\w+)\s\2)/$2/g; print $_;
As for the regex you tried $string =~ s/(\w+)(.*)\b\1/$1 $2/sig;, we have :
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: most efficient regex to delete duplicate words (boo)
by blakem (Monsignor) on Aug 14, 2001 at 02:37 UTC | |
by Ven'Tatsu (Deacon) on Aug 14, 2001 at 07:32 UTC | |
by mugwumpjism (Hermit) on Aug 14, 2001 at 03:50 UTC |