Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Matching Identical Strings In The Same Line

DZone's Guide to

Matching Identical Strings In The Same Line

·
Free Resource
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 }


Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}