Clojure - Regular Expressions re-find



re-find

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

Syntax

Following is the syntax.

(re-find pat str)

Parameters − ‘pat’ is the pattern which needs to be formed. ‘str’ is the string in which text needs to be found based on the pattern.

Return Value − A string if a match is found based on the input string and pattern.

Example

Following is an example of re-find in Clojure.

(ns clojure.examples.example
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (def pat (re-pattern "\\d+"))
   (println (re-find pat "abc123de")))
(Example)

Output

The above program produces the following output.

123
clojure_regular_expressions.htm
Advertisements