No matching definitions.

regex/regex

src/regex/regex.tur
defopaque

Regex

(Regex)

compiled PCRE2 pattern handle.

Since: 0.2.0

defopaque

Match

(Match)

result of a successful match against a Regex.

Since: 0.2.0

defn

regex-compile

(regex-compile [pattern : cstr flags : int] :)

compile a PCRE2 pattern into a reusable Regex handle.

patternPCRE2 pattern string, e.g. "(?P<year>\\d{4})-(?P<month>\\d{2})"
flagsoption flags as :int (0 for defaults, or PCRE2_CASELESS = 0x00000008)

(Result Regex cstr) -- ok(Regex) on success, err(msg) on parse failure. Free the Regex with regex-free when done.

(let [r (regex-compile "\\d+" 0)]
    (when (ok? r) (regex-match (ok-val r) "abc123")))

Since: P6 (typed as Result in 0.2.0)

defn

regex-free

(regex-free [re : Regex] :)

free a compiled Regex handle.

reRegex handle (unwrapped ok-val from regex-compile)
(regex-free (ok-val r))

Since: P6 (typed as Regex in 0.2.0)

defn

regex-match

(regex-match [re : Regex subject : cstr] :)

match a compiled Regex against a subject string (first match only).

reRegex handle from regex-compile
subjectstring to search

(Result Match cstr) -- ok(Match) on match, err(msg) on no-match or error. Use capture-at / capture-named from regex/capture to inspect.

(let [m (regex-match re "hello 42 world")]
    (when (ok? m) (capture-at (ok-val m) 0)))

Since: P6 (typed in 0.2.0)

defn

regex-match-all

(regex-match-all [re : Regex subject : cstr] :)

find all non-overlapping matches in a subject string.

reRegex handle from regex-compile
subjectstring to search

:int -- cons-list of Match handles (may be empty / nil if no matches). Each element is a Match usable with capture-at / capture-named.

(let [ms (regex-match-all re "one 1 two 2")]
    (for [m ms] (println (capture-at m 0))))

Since: P6 (typed in 0.2.0)

defn

regex-replace

(regex-replace [re : Regex subject : cstr replacement : cstr global : int] :)

replace matches of a pattern with a replacement string.

reRegex handle from regex-compile
subjectinput string
replacementreplacement string; use $1, $2 for backreferences
globalif non-zero, replace all matches; otherwise replace first only

(Result cstr cstr) -- ok(result-string) or err(message)

(regex-replace re "hello world" "there" 0)  ; replace first
  (regex-replace re "aaa" "b" 1)              ; replace all

Since: P6 (typed in 0.2.0)

defn

regex-of

(regex-of [r ptr<void>] :)

extract a typed Regex handle from an ok result returned by regex-compile.

defn

match-of

(match-of [r ptr<void>] :)

extract a typed Match handle from an ok result returned by regex-match.