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 6120091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:37:43+00:00 2026-05-23T15:37:43+00:00

I am using Ruby to open a URL and read its content. The content

  • 0

I am using Ruby to open a URL and read its content. The content type of the file I am reading is ‘text/plain’.

The issue is that this contains some characters which I want to escape. For example, one of the characters that is coming up in the plain text is “\240” which is ASCII for a hyphen.

I am curious how this is being generated, because I don’t see a hyphen anywhere in the text. Yet it exists invisibly and “\240” shows up when I use puts to print the text in the console.

Second of all, how do I escape such instances of weird characters? Ideally, I want to escape all characters which are of the form “\[some number]”. I am using

"\240".gsub(Regexp.new("\\\d+"),"")

but it doesn’t seem to work.

Are there more traditional ways of sanitizing plain text content read from opening a URL?

  • 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-05-23T15:37:44+00:00Added an answer on May 23, 2026 at 3:37 pm

    After having a play with this, I found the following regular expression which does the trick for me:

    str.gsub(/[^\x00-\x7F]/,'')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment: Ruby 1.9.2, Rails 3.0.3, Ubuntu When I try to open a URL using:
I'm trying to read the duration out of an mp3 file using ruby-mp3info and
I'm trying to download a file using Ruby and Open-URI but I'm running into
I'm trying to process content from a list of links using open-uri in ruby
I'm using the ruby serial port gem. After I open up the port I
Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey
Using Ruby 1.9.2 I need to parse a CSV file, and output lines with
I started using ruby-electric-mode. I like it except that I am used to closing
I am trying to a save a website to an HTML file using Ruby.
I have a Ruby script that generates a UTF8 CSV file remotely in a

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.