Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:05:34+00:00 2026-06-04T17:05:34+00:00

I am pasting text from a windows plain text file to a text_area. The

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:05:36+00:00Added an answer on June 4, 2026 at 5:05 pm

    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.

    def create
    @scan = Scan.new(params[:scan])
    
    #eliminate pesky carriage returns
    @scan.raw.gsub!(/\r\n?/, "")
    @scan.raw.gsub("\u000a","")
    @scan.raw.gsub!("\u000d","")
    @scan.raw.gsub!("\u0009","")
    @scan.raw.gsub!("\u000c","")
    @scan.raw.gsub!("\u0085","")
    @scan.raw.gsub!("\u2028","")
    @scan.raw.gsub!("\u2029","")
    @scan.raw.gsub!(/0A\0A/u,"")
    @scan.save!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am taking a text file from user and then posting that file back
I am having trouble passing data read from a text file to another class
I have text being passed to a function. That text can contain anything, from
I am trying to copy a selection of text from vim to another windows
I have a text in an email on a windows box that looks something
I have a problem while pasting my contents (or text) generated by Java code
Here I'm pasting my codes where I want to retrieve Bundle version from my
I have installed fckeditor and when pasting from MS Word it adds alot of
I am copying code from website matplotlib and pasting into the Vim editor in
Got a little issue where my client is pasting in content from Word into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.