So, I was messing around with RegexBuddy and discovered that capturing groups work inside lookarounds (e.g., "
(?=(captured))"), even though, of course, lookarounds don't actually match anything. Consider that by using this technique, you can return text to your application (using backreferences) which wasn't contained within your actual match (backreference 0)!
Thinking back to the regex I just posted about (which matches innermost HTML elements, supporting an infinite amount of nesting), I realized this technique could actually be used to fake an atomic grouping. So, I've added a note on the end of the last post with an improved non-atomic-group-reliant version, which sure enough is nearly identical in speed to the regex which uses a real atomic grouping.
Here's how it's done:
(?=(pattern to make atomic))\1
Basically, it uses a capturing group inside a positive lookahead (which captures but doesn't actually match anything, so the rest of the regex can't backtrack into it), followed by "
\1" (the backreference you just captured), to act just like an atomic group. That appears to produce the exactly same result as "