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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.