regexp-opt is a package that helps you write very simple regexps.
(regexp-opt '("alex" "albert" "alois" "bummer"))results in
"al\\(bert\\|ex\\|ois\\)\\|bummer"
(or
"\\(?:al\\(?:bert\\|ex\\|ois\\)\\|bummer\\)"
in Emacs 23).
From the commentary:
The “opt” in “regexp-opt” stands for “optim\\(al\\|i\\(se\\|ze\\)\\)”.
This package generates a regexp from a given list of strings (which matches one of those strings) so that the regexp generated by:
(regexp-opt strings)
is equivalent to, but more efficient than, the regexp generated by:
(mapconcat 'regexp-quote strings "\\|")
The author, SimonMarshall?, also says: