/^(?(?=((?(3)(?(?!.*\3)(?(?!((?<=(?!\3).(?=(?2)). |(?=\3)..)))(*F))))(?(?=.)(?=(.)(?1)))))(*F))/sx #### qr{ (?(DEFINE) (? (?{ print "pre: $-[0]<$&>$+[0] pos:".pos."\n" }) (?() # we have a current character to inspect (?{ print "*CUR: <$+{cur}> / $-[0]<$&>$+[0] pos:".pos."\n" }) (?(?! .* \g{cur} ) (?{ print " cur($+{cur}) doesn't repeat ahead, looking back\n" }) (?(?!(?&loopback)) (?<= (? . ) ) (?{ print " cur($+{cur}) doesn't repeat behind either, " ."FOUND SINGLE: '$+{single}'!\n" }) (*FAIL) | (?{ print " cur($+{cur}) repeats behind\n" }) ) | (?{ print " cur($+{cur}) cur repeats ahead\n" }) ) ) (?(?=.) # there are more characters, continue looping (?= (?.) (?&loopfwd) ) ) (?{ print "post: $-[0]<$&>$+[0] pos:".pos."\n" }) ) ) (?(DEFINE) (? (?<= # this lookbehind is fixed width! (? (?! \g{cur} ) . ) (?{ print " prev: <$+{prev}> / $-[0]<$&>$+[0] pos:".pos."\n" }) (?=(?&loopback)) . | (?= \g{cur} ) . . ) ) ) \A (?(?=(?&loopfwd)) (?{ print "loopfwd matched (no single found)\n" }) (*FAIL) | (?{ print "loopfwd didn't match (single found)\n" }) ) }msx