Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a solution that enables the direct use of atomic groups #3699

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

slevithan
Copy link

The catastrophic backtracking solution described where atomic groups are emulated using lookahead and backreferences is useful but can be tricky to use and error prone (e.g. when quantifying the result, or in longer patterns that rely on multiple atomic groups). So this adds a link to an easy to use solution that enables the direct use of atomic groups via (?>…) in native JS regexes.

@javascript-translate-bot javascript-translate-bot added the review needed Review needed, please approve or request changes label Jun 5, 2024
@javascript-translate-bot javascript-translate-bot requested a review from a team June 5, 2024 13:20
@CLAassistant
Copy link

CLAassistant commented Jun 5, 2024

CLA assistant check
All committers have signed the CLA.

@javascript-translate-bot javascript-translate-bot added needs +1 One more review needed and removed review needed Review needed, please approve or request changes labels Jun 6, 2024
@slevithan
Copy link
Author

I updated the PR to make some additional tweaks:

  • Atomic groups don't capture, so I changed "atomic capturing groups" to "atomic groups" (their correct name).
  • The emulation trick (with a backreference to a capturing group inside a lookahead) emulates an atomic group, not a possessive quantifier, so I corrected this. This distinction is subtle since possessive quantifiers are sugar for some common uses of atomic groups, but it is important. For example, the lookahead/capture trick accurately emulates the behavior of an atomic group like (?>…|…) which is not followed by a quantifier at all.

@slevithan slevithan changed the title Add a solution for that enables the direct use of atomic groups Add a solution that enables the direct use of atomic groups Jul 2, 2024
@smith558 smith558 self-assigned this Jul 10, 2024
@smith558 smith558 requested review from Alexandre887 and removed request for CyberAnilpatil July 10, 2024 15:16
The solution described where atomic groups are emulated using lookahead and backreferences is useful but can be tricky to use and error prone (e.g. when quantifying the result, or in longer patterns that rely on multiple atomic groups). So this adds a link to an easy to use solution that enables the direct use of atomic groups via `(?>…)` in native JS regexes.
@slevithan
Copy link
Author

Ping @Alexandre887 for review. This PR makes this (already quite informative) article even better for readers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs +1 One more review needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants