Just to make sure I understand the question, you're looking for a regex that does the equivalent of the following regex, but without (?{ }) or (??{ })? (Anything else that's not allowed?) Personally, I don't find this particular (??{ }) construct too terrible...
I played around a bit with recursion but then I was banging my head against the string 'abacbc', now I have to stop for today.
use warnings; use strict; use Algorithm::Combinatorics 'variations_with_repetition'; use Test::More; my $re = qr{ \A ( .* ) ( (??{ length $1 ? "[^".quotemeta($1)."]" : "." }) ) ( (?: (?! \2 ) . )* ) \z }msx; for my $len (1..7) { my $iter = variations_with_repetition([qw/a b c/], $len); while ( my $c = $iter->next ) { my $str = join '', @$c; my $exp = do { my %h; $h{$_}++ for @$c; my %r = reverse %h; exists $r{1} }; is $str=~$re, $exp, $str.($exp?' =~':' !~').' re' or diag explain [ \%-, map [ $-[$_], eval "\$$_", $+[$_] ], 1..@+ ]; } } done_testing;
Update: A bit of research on variable-width lookbehind: Why is variable length lookahead implemented while lookbehind is not?, Re: perl regexp question excluding strings, Not-really variable length lookbehind
In reply to Re: Regex: matching character which happens exactly once
by haukex
in thread Regex: matching character which happens exactly once
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |