I've set up a Ruby script to do some grep find/replaces on a text file. Two of them seem to work fine, and the third works as expected when I test it on Rubular, but not when I run the script. I'm just learning Ruby and programming in general, so I'm guessing there's something wrong with the script itself, not just the regex.
See the script and sample input text below. The purpose of the script is to examine a large quantity of text that will be copied from a web page, remove unnecessary parts, and add and remove tabs in certain places to set it up for use as a spreadsheet. The clear_stuff regex represents a unique set of table headers that immediately precedes the desired content. The script should match this regex with all content on the page up to and including this set of headers and remove it. At the moment, it only deletes the headers themselves, so it appears that multiline mode isn't working. I tried using the Regexp.new syntax instead of the one shown below as well, but that didn't work either.
Any ideas what's happening here?
#regexes for find/replace
add_tabs = /^(term1)/
remove_tab = /\t(\tterm2)/
clear_stuff = /.*hat\.goat\sthis thing\sthat thing\sstuff\scheese/m
#read file and replace
fileObj = File.new("input.txt", "r")
while (line = fileObj.gets)
substitute_line = line.gsub(clear_stuff, "")
substitute_line1 = substitute_line.gsub(add_tabs, "\t\t\\1")
substitute_line2 = substitute_line1.gsub(remove_tab, "\\1")
[Stuff that should get deleted]
hat.goat this thing that thing stuff cheese
[header that needs to stay]
term1 [random text - this line should be preceded by 2 tabs after output]
term2 [random text - this line should be preceded by a single tab after output]
[random text - this line should remain as is after output]