Skip to content

clojure.core/re-find

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 7 Runnable: 3
([m] [re s])

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

Examples

by nipra on . May have evaluation errors.
by OnesimusUnbound on . May have evaluation errors.
by jafingerhut on . May have evaluation errors.
by Claj on . May have evaluation errors.
by Pete Mancini on
by jafingerhut on
by jgomo3 on

Note by paomian

the regex can't be a var?

(let [regex "abc"] (re-find #a "abc"))
this will get an error!

Note by blx

@paomian: The regex can be a variable, but the variable needs to be a regex.

This works fine:

(let [regex #"abc"] (re-find regex "abc"))

because the # reader macro for declaring regexes applies to the string right after it -- without doing any kind of substitution.

You could also do

(let [regex "abc"] (re-find (re-pattern regex) "abc"))

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.