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

  • Home
  • SEARCH
  • 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 83439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:46:25+00:00 2026-05-10T21:46:25+00:00

I thought this code would work, but the regular expression doesn’t ever match the

  • 0

I thought this code would work, but the regular expression doesn’t ever match the \r\n. I have viewed the data I am reading in a hex editor and verified there really is a hex D and hex A pattern in the file.

I have also tried the regular expressions /\xD\xA/m and /\x0D\x0A/m but they also didn’t match.

This is my code right now:

   lines2 = lines.gsub( /\r\n/m, '\n' )    if ( lines == lines2 )        print 'still the same\n'    else        print 'made the change\n'    end 

In addition to alternatives, it would be nice to know what I’m doing wrong (to facilitate some learning on my part). 🙂

  • 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. 2026-05-10T21:46:26+00:00Added an answer on May 10, 2026 at 9:46 pm

    What do you get when you do puts lines? That will give you a clue.

    By default File.open opens the file in text mode, so your \r\n characters will be automatically converted to \n. Maybe that’s the reason lines are always equal to lines2. To prevent Ruby from parsing the line ends use the rb mode:

    C:\> copy con lala.txt a file with many lines ^Z  C:\> irb irb(main):001:0> text = File.open('lala.txt').read => 'a\nfile\nwith\nmany\nlines\n' irb(main):002:0> bin = File.open('lala.txt', 'rb').read => 'a\r\nfile\r\nwith\r\nmany\r\nlines\r\n' irb(main):003:0> 

    But from your question and code I see you simply need to open the file with the default modifier. You don’t need any conversion and may use the shorter File.read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I don't see anything obviously wrong with your code, but… May 11, 2026 at 10:37 am
  • added an answer Instead of relying on the collection property App Engine creates,… May 11, 2026 at 10:36 am
  • added an answer Did your template only come with a PSD file? Typically,… May 11, 2026 at 10:36 am

Related Questions

I thought this code would work, but the regular expression doesn't ever match the
I found this in the code I'm working on at the moment and thought
I thought this was asked before, but 15 minutes of searching on Google and
I thought this was pretty straight forward but I don't get the same results
I thought this would be simple, but its not working .. in both the
I thought this would have done it... $rowfetch = $DBS->{Row}->GetCharValue(meetdays); $rowfetch = /[-]/gi; printline($rowfetch);
I may be missing something here because I thought this might be really easy
Sorry, I thought this was an inheritance question: it was an ArrayList question all
To show, for example.... USER@SID > I thought this was potentially helpful to a
I would have thought this would be an easy one to Google, but I've

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.