This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro mk-named-regex-fn | |
"Given an expression that returns a string returns a function | |
that given a string returns nil if pattern did not match | |
and a map of named groups if pattern matches. | |
Usage: ((regex \"(?<name>[a-zA-Z]+)\") \"John\") => {\"name\" \"John\"}" | |
[regex-string-expression] | |
(let [regex-string (eval regex-string-expression) | |
re-group-regex #"(?<!\\)(?:\\\\)*\((?:\?<(\w+)>|[^?])" | |
pattern (re-pattern regex-string) |