Alternation in an atomic group is useless?

I know a lot of great answer about atomic grouping like Confusion with Atomic Grouping - how does it differ from Ruby regex grouping?

My question is simple: therefore alternation in an atomic group is useless, right?

Some examples:

  • a(?>bc|b)cwill never match abc, in fact he will never try to complete the bpart in()
  • (?>.*|b*)[ac]will never match any string, as it .*matches them all and is discarded.

I understand correctly?


Some test codes are perljust in case this might be useful

sub tester {
    my ($txt, $pat) = @_;
    if ($txt =~ $pat) {
        print "${pat} matches ${txt}\n";
    } else {
        print "No match\n";
    }
}

$txt = "abcc";
$pat = qr/a(?>bc|b)c/;
tester($txt, $pat);

$txt = "bbabbbabbbbc";
$pat = qr/(?>.*)c/;
tester($txt, $pat);

$pat = qr/(?>.*|b*)[ac]/;
tester($txt, $pat);

$txt = "abadcc";
$pat = qr/a(?>b|dc)c/;
tester($txt, $pat);

I found an explanation in here that seems to answer my question.

( ) RegEx, , , - , .

+4
1

.

, , . , .

disjoint, (- (?>ab|cd)).

+5

All Articles