Hacker News new | ask | show | jobs
by triska 2792 days ago
Emacs has dedicated functions that let you handle such cases more conveniently. For example, in your case, the function regexp-quote may be useful:

    (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"
2 comments

It never ceases to amaze me how much there is to emacs and emacs-lisp. After 15 years of daily use I still discover gems like this
Thankyou