DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Matching Identical Strings In The Same Line

02.05.2006
| 5091 views |
  • submit to reddit
        
Note that (\S+) refers to \2 as well as $2.


line = "some strings are identical and some strings are not identical"

line.scan(/(^|\s)(\S+)(?=\s.*?\2)/) { puts $2 }