Skip to content

Instantly share code, notes, and snippets.

@viperscape
Last active August 29, 2015 14:09
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 viperscape/baf7724e71d4150f5757 to your computer and use it in GitHub Desktop.
Save viperscape/baf7724e71d4150f5757 to your computer and use it in GitHub Desktop.
lazy regex matches
(defn lazy-re [re pp]
(let [re-m (re-matcher re pp)
re-cm #(re-find re-m)
call-lzre
(fn step []
(lazy-seq
(when-let [r (re-cm)]
(cons r
(step)))))]
(call-lzre)))
(doseq [n (lazy-re #"\{\{(.+\S*)\}\}" "{{Title}}\nsomething {{Body}}")]
(prn n))
;;["{{Title}}" "Title"]
;;["{{Body}}" "Body"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment