|No such thing as a small change|
Regex: matching character which happens exactly onceby LanX (Bishop)
|on Oct 21, 2017 at 13:46 UTC||Need Help??|
LanX has asked for the
wisdom of the Perl Monks concerning the following question:
( DISCLAIMER this is a theoretical question about pure regexes, I know how to solve this in Perl, it's a follow up to this thread)
I'm banging my head at this problem, how do I match strings where at least one character happens exactly once, with a pure regex?
(i.e. without additional Perl code, especially embedded one, and without manipulating the input)
Finding all characters which aren't repeated afterwards is easy with a lookahead assertion
but combining with a lookbehind fails, b/c variable length is not permitted
(actually already using the backreference \1 fails, since the placeholder has variable length)
So it boils down to the question:
All workarounds I found so far only work with ugly cheats, like hardcoding all cases for a fixed length string only.
I think it might be possible with recursive regexes and relative backreferences, but still ...