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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:13:42+00:00 2026-05-28T00:13:42+00:00

So… I’ve been working with WYSIWYG editors, and have realized, that they occasionally replace

  • 0

So… I’ve been working with WYSIWYG editors, and have realized, that they occasionally replace certain characters with the hex codes for that character, like the ' or the & for example.

How do I override String’s index method such that it includes these hex codes?

Like, when do somestring.index("\'hello there") how do I get it to search \' and '

note: single quote is escaped for clarity against double quotes.

what is the most efficient way to do this kind of string search?
is there something like this already built in.

Also, since I’m using external tools, I don’t really have a say in the format things are in.

  • 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-28T00:13:42+00:00Added an answer on May 28, 2026 at 12:13 am

    THE SOLUTION:

     search_reg_exp = Regexp.escape(str).gsub(/(both|options|or|more)/, "(both|options|or|more)")
    
      long_str.index(search_reg_exp)
    

    ORIGINAL ANSWER:

    String#index doesn’t just work for single characters, it can be used for a substring of any length, and you can give it a regular expression which would probably be best in this case:

    some_string    = "Russell's teapot"
    another_string = "Russell's teapot"
    
    apostrophe_expr = /'|'/
    
    some_string.index apostrophe_expr
    # => 7
    
    another_string.index apostrophe_expr
    # => 7
    

    Another option would be to just decode the HTML entities before you start manipulating the string. There are various gems for this including html_helpers:

    require 'html_helpers'
    
    another_string = "Russell's teapot"
    
    yet_another_string = HTML::EntityCoder.decode_entities another_string
    # => "Russell's teapot"
    
    yet_another_string.index "'"
    # => 7
    
    yet_another_string.index ?'  # bonus syntax tip--Ruby 1.9.1+
    # => 7
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have been making a wordpress template. i got stuck at some place... the
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I see that some rss on xml have strange strings. For example, ... is
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I would like to run a str_replace or preg_replace which looks for certain words
I have a form, one of the fields is a select field, with 5
I have a PDB file. Now it has two parts separated by TER. Before

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.