6

In this line of code I want it to match the string from 'Review Notes \50optional\51' till the end of the text file. How can I do this?

reviewNotes = contents.match(/Review Notes \50optional\51\n==================(.*?)/m)[1].strip
thisiscrazy4
  • 1,905
  • 8
  • 35
  • 58

2 Answers2

2
if subject =~ /Review Notes \\50optional\\51.*\z/m
    match = $&
else
    match = ""
end
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
1
Review Notes \50optional\51.*$
Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
  • Shouldn't the backslashes be escaped? Or does Ruby detect that this backreference doesn't exist and treats it literally? Also, `$` always matches the end of the line, not the end of the file in Ruby. There is no multiline mode (`/m` is in Ruby what `/s` is in other regex flavors). – Tim Pietzcker Aug 31 '11 at 08:11
  • @Tim, Maybe `\50` is octal? If not, it should be escaped. – Kirill Polishchuk Aug 31 '11 at 08:40
  • Yes those are octal codes for brackets. And thanks, your answer works! – thisiscrazy4 Aug 31 '11 at 16:27