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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:19:13+00:00 2026-05-27T06:19:13+00:00

I am just continuously hitting a wall with this one, I cannot solve it.

  • 0

I am just continuously hitting a wall with this one, I cannot solve it. I am trying to get a regex that executes as:

(axb|cxd)

except without repeating x in the expression (as it is really long encoding-matching expression). This is tested against a large string where I only need to match x for string replacement, so zero-width lookahead/behind is an option. Any ideas?

a,b,c, and d are reasonably small, so they can repeat if it makes the expression easier to form.

Thanks in advance.

  • 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-27T06:19:14+00:00Added an answer on May 27, 2026 at 6:19 am

    If you really don’t want to repeat x in the regular expression, then you’ll have to apply some manual search logic. You can search for x with the regular expression and then, based on where it was found, look for a before it and b after it or c before it and d after it. But, that would likely be more work than just repeating it in the regular expression as in Gabe’s answer.

    For example, you could do this:

    var re = /(a|c)x(b|d)/;
    var matches = str.match(re);
    if (matches) {
        // exclude axd or cxb
        if ((matches[1] + matches[2]).match(/ab|cd/)) {
            // found axb or cxd
        }
    }
    

    But, honestly, it seems like it would just be easier to include x twice and let the regex engine do the dirty work for you:

    if (str.match(axb|cxd)) {
        // found match
    }
    

    Or, if it’s too cumbersome to put x in the string twice, then build the regex yourself using javascript string math:

    var x = "long complicated regex";
    var re = new RegExp("a" + x + "b|c" + x + "d");
    if (str.match(re)) {
        // found match
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just seen this question , where one of the answers indicates that System.Diagnostics.Stopwatch
We have a Service that continuously collects sensor data on the phone. This service
I am basically just wondering how can I make this while loop repeat continuously
I'm trying to get Google Maps to continuously pan smoothly over unless the user
Just looking for the first step basic solution here that keeps the honest people
Just how much slower are events? I have written a streaming XML parser (that
Just found this out, so i am answering my own question :) Use a
I am developing a device that will continuously collect data from a PLC and
I've got an item that appears to continuously repaint when it exists, causing the
i am very much new to Entity Framework and i just used this in

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.