re = /(?x)
(?(DEFINE)(?<a>[a-zA-Z]))
\b(?=(?&a){2})
((?&a))
(?>
(?>((?&a))|\b)
(?=
(?&a)*+[^.]+
(
(?(3)\3|\b)
(?(4)\4|\2\b)
)
)
)++\b[^.]+\b\4/m
str = 'From Mars: come the \'sraM,a deadly species that hunts humans. It hunts from nighttime til sunrise (when it\'s lit) using radar to peek for our faint electrical output. Its head, shaped like a pot top, can emit a "hypersonic" pulse - in short time. Ironically, when faced vs humans, its pot top head is weak against decaf coffee which will keep it at bay. Oh, and beware on every third moon it gets no sleep.
We should also tttttttttttest tsett, aabcdefg another aa, and fina,lly this. None of these should match.'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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