re-matches

clojure.core

  • (re-matches re s)
Returns the match, if any, of string to pattern, using
java.util.regex.Matcher.matches(). Uses re-groups to return the
groups.

2 Examples top

  • ;; The distinction is that re-find tries to find _any part_ of the string
    ;; that matches the pattern, but re-matches only matches if the _entire_
    ;; string matches the pattern.
    user=> (re-matches #"hello" "hello, world")
    nil
    
    user=> (re-matches #"hello.*" "hello, world")
    "hello, world"
    
    user=> (re-matches #"hello, (.*)" "hello, world")
    ["hello, world" "world"]
    
  • ;; 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:4292 top

(defn re-matches
  "Returns the match, if any, of string to pattern, using
  java.util.regex.Matcher.matches().  Uses re-groups to return the
  groups."
  {:added "1.0"
   :static true}
  [^java.util.regex.Pattern re s]
    (let [m (re-matcher re s)]
      (when (. m (matches))
        (re-groups m))))
Vars in clojure.core/re-matches:
Used in 0 other vars

Comments top

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