re-seq

added
1.0

ns
clojure.core

type
function

(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.

                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.
            
                ;; separate with Camel case words and digits and
;; join with single white-space character

user=> (clojure.string/join " " (re-seq #"[A-Z][a-z]+|[0-9]+" "ManishKumar12332"))
"Manish Kumar 12332"