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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:58:11+00:00 2026-05-28T17:58:11+00:00

I am looking to match the following pattern (1) 10digits sometext (e.g. 1235873490 ABCD

  • 0

I am looking to match the following pattern

(1)

10digits sometext (e.g. 1235873490 ABCD EFGK)

In a text that might have the pattern above, as well as very similar pattern like this one

(2)

10digits sometext decimal_number (e.g. 9835873490 VBGF XMF 23.233)

How I can write the regular expression to match only pattern (1) and ignore pattern (2)?

I have looked at negative lookaheads using something like this:

(\d{10})\s*([A-Za-z0-9]+(?:\s+[A-Za-z0-9]+)(?:\s+[A-Za-z0-9]+))\s*(?!(\d+.\d+))

but cannot get it to work. Any ideas? By the way, I am using c++ boost::regex.

  • 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-28T17:58:12+00:00Added an answer on May 28, 2026 at 5:58 pm

    First, start with the straightforward version:

    (\d{10}         # 10 digits
        (?:\s+\w+)+)  # some text, separated by spaces,
                      # at least one time
    (?!\s*\d+\.\d+) # not followed by a decimal number
    

    I changed your [A-Za-z0-9] to \w for simplicity, and allowed it to occur as many times as it wants.

    However, this will also match the second string – it will gobble up the 23 at the end, then see that this doesn’t have a decimal number following (it’s followed by “.23”), so it will match.

    To prevent this, we can say that it must be followed by a space or the end of the text:

    (\d{10}(?:\s+\w+)+)
        (?=\s|$)      # it must be followed by a space or end of text
    (?!\s*\d+\.\d+)
    

    However, this still has a problem. Now, it will match up to “…XMF”, but then see it is followed by a decimal number, and backtrack. It will go back to “…VBGF” and then match, since “VBGF” isn’t followed by a decimal.

    To prevent this, we can tell the regex that it can’t backtrack once it has matched our main section:

    (?> # added '?>': not allowed to backtrack once this group is matched
        \d{10}(?:\s+\w+)+)      
    (?=\s|$)(?!\s*\d+\.\d+)
    

    Alternately, if you know that there will always be 2 parts in sometext, this will also solve the backtracking:

     (\d{10}(?:\s+\w+){2}  # can only occur twice
         )    
     (?=\s|$)(?!\s*\d+\.\d+)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a regular expression that will match text given the following requirements:
Looking for a regular expression that match the following relative URLs: All urls starts
I am looking for a regular expression that would match the following: firstname.lastname+expense@mydomain.com joe.smith+expense@mydomain.com
I'm looking to match all text in the format foo:12345 that is not contained
I am looking to match e-mail addresses in a text document for which I
I'm looking for the regex to match any string that has an opened or
I'm looking for a pattern equivalent to \w, and which doesn't match numeric pattern.
I am trying to determine what the following pattern match criteria allows me to
I'm looking for a regex that will scan a document to match a function
I am looking for a perl regex that would match vserver foo2 from the

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.