I think the simplest approach is to use an additional anchor for the match. Since $c consumes everything up to and including the newline, if you begin the match of whatever follows $c with a start-of-(embedded)-line anchor, you get the desired results for the example string given.
perl -wMstrict -le "my $c = qr{ (?> -- [^\n]* (?:\n|\z)) }xms; my $str = qq(a --b x\n x); print qq(match at positions $-[1]-), $+[1]-1 if $str =~ m{ ($c* [ ] x) }xms; " match at positions 2-9 perl -wMstrict -le "my $c = qr{ (?> -- [^\n]* (?:\n|\z)) }xms; my $str = qq(a --b x\n x); print qq(match at positions $-[1]-), $+[1]-1 if $str =~ m{ ($c* x) }xms; " match at positions 6-6 perl -wMstrict -le "my $c = qr{ (?> -- [^\n]* (?:\n|\z)) }xms; my $str = qq(a --b x\n x); print qq(match at positions $-[1]-), $+[1]-1 if $str =~ m{ ($c* ^ [ ] x) }xms; " match at positions 2-9 perl -wMstrict -le "my $c = qr{ (?> -- [^\n]* (?:\n|\z)) }xms; my $str = qq(a --b x\n x); print qq(match at positions $-[1]-), $+[1]-1 if $str =~ m{ ($c* ^ x) }xms; "
(The last example had no output, i.e., no match.)
BTW - These examples were run under Perl 5.8. The 5.10 regex possessive quantifiers might be worth investigating, but I think they are just shorthand for the (?> ... ) 'atomic' construct and would give the same results.
In reply to Re: How do I avoid regex engine bumping along inside an atomic pattern?
by AnomalousMonk
in thread How do I avoid regex engine bumping along inside an atomic pattern?
by zemane
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |