Issue
I'm trying to see if there is a way in an RE to express a match for a word consisting of a selection of given letters plus one wildcard letter.
For example, find all words in the system dictionary containing any mix of C, O, I, and any one other letter, in any order, without reusing a letter already matched, and using up all provided letters. So in this case, an RE would need to match
coif
coil
coin
coir
foci
icon
loci
rico
and maybe others that I am missing.
I'm not sufficient of a mathematical logician to know if this is even possible in a regexp.
It doesn't have to be done entirely in a regexp — if it uses several stages that's fine; it can be postprocessed in a script. I can't find a representation like '^[oci.]*$'
(wrong) that even begins to address this.
Solution
Since you said It doesn't have to be done entirely in a regexp
, this will work using any POSIX awk:
awk '/^.{4}$/ && /c/ && /o/ && /i/ && /[^coi]/' file
Answered By - Ed Morton