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

The Archive Base Latest Questions

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

I have a long RegEx that is working, but I have a section at

  • 0

I have a long RegEx that is working, but I have a section at the end that is perplexing me. I have a scenario where I am parsing some HTML and one of two scenarios can happen. Either the pattern I am searching for ends with a X followed immediately by a single digit or it’s a  . Here’s the RegEx fragment:

(X(\d+)| )

As you might have noticed, I don’t care about the X or the  , I just want to capture the digit if it’s there. It appears that in order to use the |, I have to use a capture group. So now I get BOTH X5 AND 5 if that pattern exists. I really just want the digit captured if it’s there.

Thanks!

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

    To get the effect of grouping, without the effect of capturing, use the (?:...) notation:

    (?:X(\d+)| )
    

    This is equivalent to what you wrote, except that it doesn’t create a capture group for X5, only for 5.

    (By the way, you say “a single digit”, but your regex has \d+ rather than \d, so it can actually match multiple digits.)

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

Sidebar

Related Questions

Long story short, I have two regex patterns. One pattern matches things that I
Is this actually doable? I have some very long regex pattern rules that are
I have a regex that is going to end up being a bit long
I have some strings that need a-strippin': ÜT: 9.996636,76.294363 Tons of long strings of
I have this regex working when I test it in PHP but it doesn't
I have the following regex (long, I know): (?-mix:((?-mix:(?-mix:\{\%).*?(?-mix:\%\})|(?-mix:\{\{).*?(?-mix:\}\}?)) |(?-mix:\{\{|\{\%))) that I'm using to
I have long-lasting TCP connection between two computers (second not under my control). Second
Currently I have Long Pres Gesture Recognizers on four different TableViews (two in each
One thing with which I have long had problems, within the CakePHP framework, is
I've recently started coding in C++, but I have long time writing in C.

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.