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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:19:27+00:00 2026-06-04T17:19:27+00:00

Are regex atomic groups distributive? I.e. is (?>A?B?) always equivalent to (?>A?)(?>B?) ? If

  • 0

Are regex atomic groups distributive?

I.e. is (?>A?B?) always equivalent to (?>A?)(?>B?)?

If not please provide a counter example.

  • 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-06-04T17:19:28+00:00Added an answer on June 4, 2026 at 5:19 pm

    Atomic groups in general

    1. The atomic group (?>regex1|regex2|regex3) takes only the first successful match within it. In other words, it doesn’t allow backtracking.

    2. Regexes are evaluated left-to-right, so you express the order you intend things to match. The engine starts at the first position, trying to make a successful match, backtracking if necessary. If any path through the expression would lead to a successful match, then it will match at that position.

    3. Atomic groups are not distributive. Consider these patterns evaluated over ABC:
      (?>(AB?))(?>(BC)) (no match) and (?>(AB?)(BC)) (matches ABC).

    Atomic Groups with all optional components

    But, your scenario where both parts are optional may be different.

    Considering an atomic group with 2 greedy optional parts A and B ((A)? and (B)?). At any position, if A matches, it can move on to evaluate the optional B. Otherwise, if A doesn’t match, that’s fine, too because it’s optional. Therefore, (A)? matches at any position. The same logic applies for the optional B. The question remaining is whether there can be any difference in backtracking.

    In the case of all optional parts ((?>A?B?)), since each part always matches, there’s no reason to backtrack within the atomic group, so it will always match. Then, since it is in an atomic group, it is prohibited from backtracking.

    In the case of separate atomic groups ((?>A?)(?>B?)), each part always matches, and the engine is prohibited from backtracking in either case. This means the results will be the same.

    To reiterate, the engine can only use the first possible match in (?>A?)(?>B?), which will always be the same match as the first possible match in (?>A?B?). Thus, if my reasoning is correct,for this special case, the matches will be the same for multiple optional atomic groups as a single atomic group with both optional components.

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

Sidebar

Related Questions

regex not working as wanted Code example: widgetCSS = #widgetpuffimg{width:100%;position:relative;display:block;background:url(/images/small-banner/Dog-Activity-BXP135285s.jpg) no-repeat 50% 0; height:220px;}
I have written following regex But its not working. Can you please help me?
RegEx has always confused me. I have a string like this: IDE\DiskDJ205GA20_____________________________A3VS____\5&1003ca0&0&0.0.0 Or Sometimes
Regex: \b< low= number= low=>\b Example string: <b22>Aquí se muestran algunos síntomas < low=
Regex to remove everything outside the { } for example: before: |loader|1|2|3|4|5|6|7|8|9|{data : some
Regex Expression for finding a string which has one @ and should not start
Regex fun again... Take for example http://something.com/en/page I want to test for an exact
This regex below captures the -aaaa and -cccc but not the -eee How can
With Regex::Replace we can use $1, $2, ... to match corresponding groups. But how
Regex for not allowing single quotes and double quotes in javascript .

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.