Skip to content
Verbal-Exprejon is a Clojure library that helps you build complex regexes without any regex
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Verbal Exprejon

VerbalExpressions with a lisp

travis travis


Create a Regex

(def url
  (->> (then "http")
       (maybe "s")
       (then "://")
       (maybe "www.")
       (anything-but " ")

(re-matches url "")

Create your own midleware

A middleware is a function that takes a regex as its last parameter, and output a regex.

; Match a `domain` url like

(defpattern url?
  "Match if it is a url"
  (->>  (then "http")
        (maybe "s")
        (then "://")
        (maybe "www.")
        (then domain)
        (anything-but " ")))

Reuse your middlewares

Match stuff like facebook or google

(defpattern url-name
  "Match if it is a domain url followed by its name"
  (->>  (url? domain)
        (then " ")
        (then domain)))

(def match (matcher url-name "google"))
(println (match " google"))

;; -> true


(defpattern hour-pattern
  "Matches an hour"
  [] (->> (interval [\0 \9])
          (times [1 2])
          (maybe (OR ["h" (->> (then "hour") (maybe "s"))]))))

(defpattern minute-pattern
  "Matches a minute"
  [] (->> (interval [\0 \9])
          (times [1 2])
          (maybe (OR ["m" (->> (then "minute") (maybe "s"))]))))

(defpattern second-pattern
  "Matches a second"
  [] (->> (interval [\0 \9])
          (times [1 2])
          (maybe (OR ["s" (->> (then "second") (maybe "s"))]))))

(defpattern time-separator
  "Matches the separation between hours, minutes and seconds"
  [] (maybe (->> (any-blank)
                 (maybe (OR ["and" " " ", " ":"]))

(defpattern time-pattern
  "Matches a time"
  [] (->> (maybe (->> (hour)
          (maybe (->> (minute)
          (maybe (second))))

(def time? (matcher time-pattern))

(defn testit
  (time? time))

(testit "12h")
(testit "12h5")
(testit "12h05")
(testit "12h30m")
(testit "12:07")
(testit "12hours")
(testit "12hours and 3 minutes")
(testit "12:5:4")
(testit "12h and 5 minutes")
(testit "5 hours")
(testit "12 minutes")
(testit "12 minutes and 5 seconds")
(testit "5s")


(then "string"):

Matches the string literally

(maybe "string"):

Matches the string if any


Matches anything

(anything-but "string"):

Matches anything except the provided value


Matches the previous middleware one ore more times


Matches the previous middleware zero or more times

(any "letters"):

Matches any letter from the provided string


Matches any blank characters including line breaks, spaces and tabs


Matches the end of a line


Matches the start of a line


Matches a \n

(interval [characters]):

Matches the pairs ranges provided. Examples:

;; matches any letter between a-z and A-Z
(interval \a \z \A \Z)


Matches a tabulation


Matches a word (case insensitive)

(OR [vector]):

Matches the first matching expression in the vector

(times [start end]):

Matches the previous middleware from start times to end times Example:

; [0-9]{1,3}

(interval \0 \9)
(times [1 3])

(words-split-by [delimiters]):

Matches a sequence of words split by any delimiters in the provided vector


Matches a sequence of words split by spaces


This has been done by a Clojure newbie.

Copyright © 2016 Guillaume Badi

Distributed under the MIT License

You can’t perform that action at this time.