re = /^(?>[^\w\n]*(\w++)(?=.*\R(\2?+[^\w\n]*\1\b)))+[^\w\n]*\R(?=\2[^\w\n]*$)/mi
str = 'Rough work iconoclasm but the only way to get the truth. Oliver Wendell Holmes
Rough work, iconoclasm, but the only way to get the truth. Oliver Wendell Holmes
Rule No. 1: Never lose money. Rule No. 2: Never forget rule No. 1. Warren Buffett
Rule No.1: Never lose money. Rule No.2: Never forget rule No.1. Warren Buffett
Self-esteem isn\'t everything, it\'s just that there\'s nothing without it. Gloria Steinem
Self-esteem isn\'t everything it\'s just that there\'s nothing without it. Gloria Steinem
You said she\'s a senior? Babe we\'re all crazy.
You said, she\'s a senior! Babe we\'re ALL crazy.
You said, she\'s a senior? Babe we\'re ALL crazy!
a
a a
a a a
a
a b
a b c
a b
a'
subst = ''
result = str.gsub(re, subst)
# Print the result of the substitution
puts result
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html