Forgot to add, you can solve this another way (taking the abc example):
grep ‘^...$’ | grep ‘[^a]*a[^a]*’ | grep ‘[^b]*b[^b]*’ | grep ‘[^c]*c[^c]*’
This will scale better for large N and easier to grok and probably what
Dave had in mind!
On May 29, 2022, at 11:35 PM, Michael Kjörling <michael@kjorling.se> wrote:
On 29 May 2022 21:47 -0700, from bakul@iitbombay.org (Bakul Shah):You can write a program to generate all permutations and use that as your regexp.
For example abc maps to abc|acb|bac|bca|cab|cba. You can rearrange it as
a(bc|cb)|b(ac|ca)|c(ab|ba) to see how an n letter permutation is computed from
permutations of n-1 letters. I don’t think you can do better.
I was trying to do something very similar using procmail regexes sometime ago, only with strings instead of individual characters (forparsing and matching on arbitrarily-ordered, comma-separated valueswithin a header). I never did come up with a good solution.-- Michael Kjörling • https://michael.kjorling.se • michael@kjorling.se “Remember when, on the Internet, nobody cared that you were a dog?”