I have a pool of characters and I want to match all the words which are anagrams of those chars or of a subset of those chars using a regular expression.
Example: given the string "ACNE" the regex should give me these results:
I've tried this solution /b[acne]{1,4}/b
but it accepts multiple repetitions of single chars.
What can I do to take each char at most one time?
The sub-anagrams of the word "acne" are the words that
acne
a
more than oncec
more than oncen
more than oncee
more than onceCompiling this into a regex:
^(?!.*a.*a)(?!.*c.*c)(?!.*n.*n)(?!.*e.*e)[acne]*$
Test: regexpal
Alternatively, since "acne" does not contain any letter more than once, the sub-anagrams of the word "acne" are the words that
acne
Compiling this into a regex:
^(?!.*(.).*\1)[acne]*$
Test: regexpal
Note: the sub-anagrams of the word "magmoid" can be matched as
^(?!.*([agoid]).*\1)(?!(.*m){3})[magoid]*$
(do not contain any of agoid
more than once, and do not contain m
more than twice)