re-seq

clojure.core

  • (re-seq re s)
Returns a lazy sequence of successive matches of pattern in string,
using java.util.regex.Matcher.find(), each such match processed with
re-groups.

4 Examples top

  • user=> (re-seq #"\d" "clojure 1.1.0")
    ("1" "1" "0")
    
  • ;; Get a sequence of words out of a string.
    user=> (re-seq #"\w+" "mary had a little lamb")
    ("mary" "had" "a" "little" "lamb")
    
  • ;; Parenthesized groups in the regex cause each returned match to be a
    ;; vector of matched strings.  See re-find for more examples.
    user=> (def line " RX pkts:18 err:5 drop:48")
    #'user/line
    
    user=> (re-seq #"(\S+):(\d+)" line)
    (["pkts:18" "pkts" "18"] ["err:5" "err" "5"] ["drop:48" "drop" "48"])
    
  • ;; Note: See clojure.core/subs for discussion of behavior of substrings
    ;; holding onto references of the original strings, which can
    ;; significantly affect your memory usage in some cases.
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4280 top

(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))))))))
Vars in clojure.core/re-seq:
Used in 0 other vars

Comments top

No comments for re-seq. Log in to add a comment.