Regex composition library

Hi, I’d love some feedback on the usefulness of this:

(re/and #"a" #"b") 
=> #"(ab)"

(re/or #"a" (re-pattern "b"))
=> #"(a|b)a"

(re/or #"a" (re/and #"b"))
 => #"(a|(b))"

(def def-re #"bc")
(let [local-re #"ef"]
  (re/or def-re local-re))
=> #"(bcd|bcd)"

cheers
Colin

2 Likes

Is the purpose of this to make regex more readable?

I like it! I imagine this can be pretty handy sometimes.

It also reminds me a bit of Emacs’s rx macro

Yep also allows re-use and is particularly handy for clojure.spec.

Reminds me of https://www.npmjs.com/package/verbal-expressions. It may exist in other languages (Ruby, Java ?). May be a source of inspiration.