re = /^(?:Name|Email|Operator|Start Time|End Time|Product\/Service|Phone|(?:Company?)).*$/m
str = 'Name: Tan
Email: pk.tan@my.rlb.com
Operator: Jeeva
Start Time: 07/01/2014 14:43:47
End Time: 07/01/2014 15:35:22
Product/Service: 5 Gallon Water Delivery
Phone: 62079991
Company: RL Bersepadu Sdn Bhd
Some other field won\'t work:scskcnskcnskcnk
Name: Tan
Email: pk.tan@my.rlb.com
Operator: Jeeva
Start Time: 07/01/2014 14:43:47
End Time: 07/01/2014 15:35:22
Product/Service: 5 Gallon Water Delivery
Phone: 62079991
See Company missing here: Above things are matching
'
# 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