re = /(ประเทศ)|(อเมริกา|เกาหลีใต้|เกาหลีเหนือ|ฝรั่งเศส|อิตาลี)|ประเทศ.*/m
str = 'ประเทศอเมริกาเป็นประเทศที่ดี
ประเทศเกาหลีใต้เป็นประเทศที่ดี
เกาหลีใต้คือประเทศ
ประเทศเกาหลีเหนือคือประเทศสวยงาม
ประเทศญี่ปุ่น
ประเทศอเมรกาเป็นประเทศที่ดี
เมืองที่สวยงามคือประเทศที่ดีงามอย่างฝรั่งเศสแต่ก็ไม่ได้มากไปกว่าอิตาลีที่เป็นประเทศประเทศหนึ่งเหมือนกัน
ประเทศรักสงบ'
# 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