How can I highlight consecutive duplicate words with a Perl regular expression?

Posted by murugaperumal on Stack Overflow See other posts from Stack Overflow or by murugaperumal
Published on 2010-03-24T03:51:55Z Indexed on 2010/03/25 0:13 UTC
Read the original article Hit count: 638

Filed under:
|

I want a Perl regular expression that will match duplicated words in a string.

Given the following input:

$str = "Thus joyful Troy Troy maintained the the watch of night..."

I would like the following output:

Thus joyful [Troy Troy] maintained [the the] watch of night...

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex