I received a desktop day-to-day calendar with puzzles. One such puzzle was deciphering a quote where the letters were substituted with symbols. I used some RegExs to find longer words, then used the returned words to solve smaller words. In the puzzle, white background symbols were vowels (including 'y') and shaded background symbols were consonants.I'll use random letters below where bolded means consonant, plain means vowel, and italicized means the letter was given in the directions.BOQQEThe example above was deciphered as happy ('e' was already given in the puzzle) by using the RegEx egrep -i '^[bcdfghjklmnpqrstvwxz][aiouy][bcdfghjklmnpqrstvwxz]{2}[aiouy]$' wordsThere were a lot of results, but I feel I could have made the RegEx better by specifying the RegEx logically as Char 1 is a consonantChar 2 is a vowel, but not 'e' because that was given in the directions.Chars 3 & 4 are the same consonant, but are different from char 1.Char 5 is a vowel, but different from char 2.Another example would beO R e W Y D O nwhere I used the grep statementegrep -i '^([aiouy])[bcdfghjklmnpqrstvwxz]e[bcdfghjklmnpqrstvwxz][aiouy][bcdfghjklmnpqrstvwxz]\1n$' wordsto logically define the search asChar 1 is a vowel, and is a captured group because the same char appears later in the word.Char 2 is a consonant.Char 3 is 'e', given.Char 4 is a consonant.Char 5 is a vowel.Char 6 is a consonant.Char 7 is the same vowel as Char 1.Char 8 is 'n', given.Fortunately, the grep statement returned one word, American (The cipher-text was a movie quote). I would like to have been able to specify in the RegEx that Char 4 is a consonant and not the same as char 2, char 5 is a vowel and not the same as char 1, etc.Is it possible to ask this kind of pattern matching with RegExs? I'm aware of the (x|y) syntax to state that a character may be 'x' or 'y', but I don't know of the syntax, if it exists, to specify (!x) & y
Regular Expression to match (not x) and y (!x & y)
scripting;regular expression;search
You can using perl regular expressions that have negative look-aheads.$ grep -Pi '^([aeiouy])([bcdfghjklmnpqrstvwxz])e(?!\2)([bcdfghjklmnpqrstvwxz])(?!\1)([aeiouy])(?!\2)(?!\3)([bcdfghjklmnpqrstvwxz])\1n$' /usr/share/dict/wordsAmericanamericaneverymenExpanded:$ perl -lnE '    BEGIN { $vowel = qr/[aeiouy]/i; $consonant = qr/[bcdfghjklmnpqrstvwxz]/i }    say if /^ ($vowel)                  # vowel              ($consonant)              # consonant              e                         # literal              (?!\2)($consonant)        # different consonant              (?!\1)($vowel)            # different vowel              (?!\2)(?!\3)($consonant)  # 3rd different consonant              \1                        # first vowel again              n                         # literal            $/xi' /usr/share/dict/wordsAmericanamericaneverymenThe BOQQE example would begrep -Pi '^([bcdfghjklmnpqrstvwxz])([aiouy])(?!\1)([bcdfghjklmnpqrstvwxz])\3(?!\2)([aiouy])$' /usr/share/dict/wordswhich returns 779 results (444 case sensitive) with my dictionary.