gists/gists/xr-for-readable-regular-expressions.org

128 lines
3.5 KiB
Org Mode

If you look for the value of =org-link-any-re=, you'll see this beauty:
#+begin_example
"\\(\\[\\[\\(\\(?:[^][\\]\\|\\\\\\(?:\\\\\\\\\\)*[][]\\|\\\\+[^][]\\)+\\)]\\(?:\\[\\([^z-a]+?\\)]\\)?]\\)\\|\\(<\\(bibtex\\|elisp\\|f\\(?:ile\\(?:\\+\\(?:\\(?:emac\\|sy\\)s\\)\\)?\\|tp\\)\\|h\\(?:elp\\|ttps?\\)\\|id\\|mai\\(?:lto\\|rix\\)\\|news\\|org-ql-search\\|shell\\):\\([^>
]*\\(?:
[ ]*[^>
][^>
]*\\)*\\)>\\)\\|\\(\\(?:\\<\\(?:\\(bibtex\\|elisp\\|f\\(?:ile\\(?:\\+\\(?:\\(?:emac\\|sy\\)s\\)\\)?\\|tp\\)\\|h\\(?:elp\\|ttps?\\)\\|id\\|mai\\(?:lto\\|rix\\)\\|news\\|org-ql-search\\|shell\\)\\):\\(\\(?:[^][
()<>]\\|(\\(?:[^][
()<>]\\|([^][
()<>]*)\\)*)\\)+\\(?:[^[:punct:]
]\\|/\\|(\\(?:[^][
()<>]\\|([^][
()<>]*)\\)*)\\)\\)\\)\\)"
#+end_example
[[https://github.com/mattiase/xr][xr]] to the rescue:
#+begin_src elisp
(pp-to-string (xr org-link-any-re))
#+end_src
#+RESULTS:
#+begin_example
(or
(group "[["
(group
(one-or-more
(or
(not
(any "[\\]"))
(seq "\\"
(zero-or-more "\\\\")
(any "[]"))
(seq
(one-or-more "\\")
(not
(any "[]"))))))
"]"
(opt "["
(group
(+\? anything))
"]")
"]")
(group "<"
(group
(or "bibtex" "elisp"
(seq "f"
(or
(seq "ile"
(opt "+"
(or "emac" "sy")
"s"))
"tp"))
(seq "h"
(or "elp"
(seq "ttp"
(opt "s"))))
"id"
(seq "mai"
(or "lto" "rix"))
"news" "org-ql-search" "shell"))
":"
(group
(zero-or-more
(not
(any "\n>")))
(zero-or-more "\n"
(zero-or-more
(any " "))
(not
(any " \n >"))
(zero-or-more
(not
(any "\n>")))))
">")
(group bow
(group
(or "bibtex" "elisp"
(seq "f"
(or
(seq "ile"
(opt "+"
(or "emac" "sy")
"s"))
"tp"))
(seq "h"
(or "elp"
(seq "ttp"
(opt "s"))))
"id"
(seq "mai"
(or "lto" "rix"))
"news" "org-ql-search" "shell"))
":"
(group
(one-or-more
(or
(not
(any " \n ()<>[]"))
(seq "("
(zero-or-more
(or
(not
(any " \n ()<>[]"))
(seq "("
(zero-or-more
(not
(any " \n ()<>[]")))
")")))
")")))
(or
(not
(any " \n " punct))
"/"
(seq "("
(zero-or-more
(or
(not
(any " \n ()<>[]"))
(seq "("
(zero-or-more
(not
(any " \n ()<>[]")))
")")))
")")))))
#+end_example