(regexp-quote "\\") ⇒ "\\\\"
In addition, structured data are often better represented as trees. In Emacs, you can use the function "rx" to translate Lisp forms from a dedicated tree-based mini language into regexp strings. The primary advantage is that you can more readily reflect the logic of the intended regular expression in this way.For example:
(rx (or "a" "b")) ⇒ "[ab]"
and: (rx (and (or "a" "b" "test") "c")) ⇒ "\\(?:test\\|[ab]\\)c"