re = /(?:google|yahoo)(?:\.com)?(*SKIP)(*F)|/m
str = ' I like foobar.com
I like google.com and foobar.com
I like foobar.com and google.com
I like foobargoogle.com and googlefoobar.com
I like yahoo.com and foobar.com
I like foobar.com and yahoo.com
I like foobaryahoo.com and yahoofoobar.com
I like yahoo.com
I like foobaryahoo.com
I like google.com
I like foobargoogle.com
I like google.com and yahoo.com
I like foobargoogle.com and foobaryahoo.com
'
# 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