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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:32:40+00:00 2026-05-26T06:32:40+00:00

I have simplified the examples. Say I have a string containing the code for

  • 0

I have simplified the examples. Say I have a string containing the code for a regex. I would like the regex to match a literal dot and thus I want it to be:

\.

So I create the following Ruby string:

"\\."

However when I use it with Regexp.union to create my regex, I get this:

irb(main):017:0> Regexp.union("\\.")
=> /\\\./

That will match a slash followed by a dot, not just a single dot. Compare the previous result to this:

irb(main):018:0> Regexp.new("\\.")
=> /\./

which gives the Regexp I want but without the needed union.

Could you explain why Ruby acts like that and how to make the correct union of regexes ? The context of utilization is that of importing JSON strings describing regexes and union-ing them in Ruby.

  • 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-26T06:32:40+00:00Added an answer on May 26, 2026 at 6:32 am

    Passing a string to Regexp.union is designed to match that string literally. There is no need to escape it, Regexp.escape is already called internally.

    Regexp.union(".")
    #=> /\./
    

    If you want to pass regular expressions to Regexp.union, don’t use strings:

    Regexp.union(Regexp.new("\\."))
    #=> /\./
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a table like this (this is just a simplified example,
Let's say I have a bunch of text like this (simplified example, but you
I have a simplified ajay script, from which I have removed all nonrelevant code.
The basic idea is very easy. Simplified you could say... a snake like line
I have a challenging problem where I would like to use reflection on my
I have encountered a working (with XLC8 and MSFT9 compilers) piece of code, containing
[Note : I've simplified my example for clarity] Let's say that I have a
Let's say I have an xml file like this: <root> <a><b><c> w </c></b></a> <x><y><z>
In my simplified example of what I'm actually doing, let's say I have 2
My simplified and contrived example is the following:- Lets say that I want to

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.