3 ms·
Emacs has two packages called rx and xr. They allow you to write regexes in an sexp syntax and translate between that and conventional regex syntax. Furthermore
by nemoniac 2y ago
Emacs has two packages called rx and xr. They allow you to write regexes in an sexp syntax and translate between that and conventional regex syntax. Furthermore you can define regex snippets and compose them into new ones. This more than anything can give you a handle on how a regex is composed.
For example
"\\`\\(?:[^^]\\|\\^\\(?: \\*\\|\\[\\)\\)"
can be written as
(: bos
(| (not (in "^"))
(: "^"
(| " *" "["))))
Emacs also has other features to highlight matches and groups to help understand regexes better.
https://www.emacswiki.org/emacs/Rx_Notation https://www.emacswiki.org/emacs/Rx_Notation
https://github.com/mattiase/xr https://github.com/mattiase/xr
https://www.emacswiki.org/emacs/RegularExpression https://www.emacswiki.org/emacs/RegularExpression