in reply to Re: Nonrepeating characters in an RE (updated)
in thread Nonrepeating characters in an RE
I think it's not so bad doing it with a regexp if you're generating it programmatically. And dealing with it via split is easy when all letters must be distinct, but also gets more complex when you have to honour the template.
I think the direct version for the given template would look something like the below, which doesn't look too hard to generate programmatically either for this template or for other templates more generally:
m{ (.) (?!\1) (.) (?!\1|\2) (.) (?!\1|\2|\3) (.) (?!\1|\2|\3|\4) (.) (?!\1|\2|\3|\4|\5) (.) \1 }x
For your update version, thanks - I've not noticed before that we have \g-1 (though I think I'd want to add the optional braces - it doesn't look remotely atomic to me without them). But I believe your example is also for "all distinct letters", it isn't clear to me how you'd use it for BernieC's templates.
For performance: I'm assuming this is for matching something like English words in a dictionary, so the length is unlikely to be a problem - I'd look for a different approach if the templates were commonly going to have more than 10-20 distinct letters in them. There's a lot gained by the fact that matching a regexp is a single perl op: a split-based solution is likely to lose a lot more on the op overhead than it gains on the algorithmic complexity, if the target really is something like dictionary words.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Nonrepeating characters in an RE (updated)
by AnomalousMonk (Archbishop) on Aug 16, 2022 at 07:27 UTC | |
Re^3: Nonrepeating characters in an RE (updated)
by LanX (Saint) on Aug 16, 2022 at 14:30 UTC | |
Re^3: Nonrepeating characters in an RE (simple)
by LanX (Saint) on Aug 16, 2022 at 09:11 UTC | |
by hv (Prior) on Aug 16, 2022 at 12:54 UTC | |
by BillKSmith (Monsignor) on Aug 16, 2022 at 13:54 UTC | |
by LanX (Saint) on Aug 16, 2022 at 12:58 UTC |