re = /^.*\.[^.\n]*Math[^.\n]*\..*$/m
str = 'Grade 8.Maths Test.Maths
Grade 8.Maths Test.Maths
Grade 6.Maths Formative Assessment.NA
Grade 3.Multiplication new.Mathematics
Grade 3.Demo Adaptive Module.Mathematics
Grade 4.Poetry.English
Maths 4.Primary.Maths
Maths 5.Primary.Concepts
Grade 8.English Math Word.English'
# 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