Regex, how to match multiple lines?
You can use the /m modifier to enable multiline mode (i.e. to allow . to match newlines), and you can use ? to perform non-greedy matching: message = <<-MSG Random Line 1 Random Line 2 From: person@example.com Date: 01-01-2011 To: friend@example.com Subject: This is the subject line Random Line 3 Random Line 4 MSG message.match(/(From:.*Subject.*?)\n/m)[1] … Read more