(split s re)
(split s re limit)
Splits string on a regular expression. Optional argument limit is
the maximum number of splits. Not lazy. Returns vector of the splits.
Source
(defn
split
"Splits string on a regular expression. Optional argument limit is\n the maximum number of splits. Not lazy. Returns vector of the splits."
([s re] (split s re 0))
([s re limit]
(discard-trailing-if-needed
limit
(if
(identical? "/(?:)/" (str re))
(split-with-empty-regex s limit)
(if
(< limit 1)
(vec (.split (str s) re))
(loop
[s s limit limit parts []]
(if
(== 1 limit)
(conj parts s)
(let
[m (re-find re s)]
(if-not
(nil? m)
(let
[index (.indexOf s m)]
(recur
(.substring s (+ index (count m)))
(dec limit)
(conj parts (.substring s 0 index))))
(conj parts s))))))))))