Skip to content

Instantly share code, notes, and snippets.

@sw1nn
Created April 1, 2020 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sw1nn/1d9e6bf0ed76309021caed9c3b9fb457 to your computer and use it in GitHub Desktop.
Save sw1nn/1d9e6bf0ed76309021caed9c3b9fb457 to your computer and use it in GitHub Desktop.
(defn re-seq
"Returns a lazy sequence of successive matches of pattern in string,
using java.util.regex.Matcher.find(), each such match processed with
re-groups."
{:added "1.0"
:static true}
[^java.util.regex.Pattern re s]
(let [m (re-matcher re s)]
((fn step []
(when (. m (find))
(cons (re-groups m) (lazy-seq (step))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment