I\'m trying to search for the word Gadaffi. What\'s the best regular expression to search for this?
My best attempt so far is:
\\b[KG]h?add?af?fi$\\
Easy... (Qadaffi|Khadafy|Qadafi|...)... it's self-documented, maintainable, and assuming your regexp engine actually compiles regular expressions (rather than interpreting them), it will compile to the same DFA that a more obfuscated solution would.
Writing compact regular expressions is like using short variable names to speed up a program. It only helps if your compiler is brain-dead.