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

The Archive Base Latest Questions

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

Regexp: (?=(\d+))\w+\1 String: 456×56 Hi, I am not getting the concept, how this regex

  • 0

Regexp: (?=(\d+))\w+\1
String: 456x56

Hi,

I am not getting the concept, how this regex matches “56×56” in the string “456×56”.

  1. The lookaround, (?=(\d+)), captures 456 and put into \1, for (\d+)
  2. The wordcharacter, \w+, matches the whole string(“456×56”)
  3. \1, which is 456, should be followed by \w+
  4. After backtracking the string, it should not find a match, as there is no “456” preceded by a word character

However the regexp matches 56×56.

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

    You don’t anchor your regex, as has been said. Another problem is that \w also matches digits… Now look at how the regex engine proceeds to match with your input:

    # begin
    regex: |(?=(\d+))\w+\1
    input: |456x56
    # lookahead (first group = '456')
    regex: (?=(\d+))|\w+\1
    input: |456x56 
    # \w+
    regex: (?=(\d+))\w+|\1
    input: 456x56|
    # \1 cannot be satisfied: backtrack on \w+
    regex: (?=(\d+))\w+|\1
    input: 456x5|6 
    # And again, and again... Until the beginning of the input: \1 cannot match
    # Regex engine therefore decides to start from the next character:
    regex: |(?=(\d+))\w+\1
    input: 4|56x56
    # lookahead (first group = '56')
    regex: (?=(\d+))|\w+\1
    input: 4|56x56
    # \w+
    regex: (?=(\d+))\w+|\1
    input: 456x56|
    # \1 cannot be satisfied: backtrack
    regex: (?=(\d+))\w+|\1
    input: 456x5|6
    # \1 cannot be satisfied: backtrack
    regex: (?=(\d+))\w+|\1
    input: 456x|56
    # \1 satified: match
    regex: (?=(\d+))\w+\1|
    input: 4<56x56>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I write a regex that match this 123/456 123/456/? but not this
I can't seem to find a function that captures and returns a regex'ed string.
I have a string like this: a word {{bla|123|456}} another {{bli|789|123}} some more text
I tried this code: public static void main(String[] args) throws Exception { String regexp
Is there a way to run a regexp-string replace on the current line in
i need a regexp to match only single / in a string in PHP.
I've found a Perl regexp that can check if a string is UTF-8 (the
im new with regexp, so can i ask for some assistance Using string.replace function
I'm a bit rusty on my regexp and Javascript. I have the following string
I'm having trouble coming up with the correct regex string to remove a sequence

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.