I am pasting text from a windows plain text file to a text_area. The following regex works on that text in rails only when I manually remove the CRLF line returns from the text in wordpad:
@scan.raw.scan(/(?<=stamps\|\|[a-z,0-9,A-Z])(.*?)(?=\|time)/).each do |body|
The gsub I found in various forums to remove line endings is leaving something behind that confuses the regex:
(from the model)
before_create :remove_returns
def remove_returns
#get rid of pesky carriage returns
raw.gsub!(/\r\n?/, "")
end
The line returns show as CRLF when I open the plain text file in question in Notepad++.
Another clue: the output from the rails console when I call the object shows the line returns as some kind of tab-like character, or maybe two spaces, but when I view the object in the show view in the browser it appears as though the character has been removed, even though the regex still does not function.
The problem turned out to be that I was removing the line endings with a before_create method in the model, followed by another method (also before_create) that was relying on having the line endings removed. I performed the action in the controller followed by a “save!” instead.