Next: , Previous: , Up: srfi regexps syntax   [Index]


2.39.7.3 Repeating patterns

(optional sre ...)
(? sre ...)

An optional pattern; matches 1 or 0 times.

(regexp-search '(: "match" (? "es") "!") "matches!")
⇒ #<regexp-match>

(regexp-search '(: "match" (? "es") "!") "match!")
⇒ #<regexp-match>

(regexp-search '(: "match" (? "es") "!") "matche!")
⇒ #f
(zero-or-more sre ...)
(* sre ...)

Kleene star; matches 0 or more times.

(regexp-search '(: "<" (* (~ #\>)) ">") "<html>")
⇒ #<regexp-match>

(regexp-search '(: "<" (* (~ #\>)) ">") "<>")
⇒ #<regexp-match>

(regexp-search '(: "<" (* (~ #\>)) ">") "<html")
⇒ #f
(one-or-more sre ...)
(+ sre ...)

1 or more matches. Like ‘*’ but requires at least a single match.

(regexp-search '(: "<" (+ (~ #\>)) ">") "<html>")
⇒ #<regexp-match>

(regexp-search '(: "<" (+ (~ #\>)) ">") "<a>")
⇒ #<regexp-match>

(regexp-search '(: "<" (+ (~ #\>)) ">") "<>")
⇒ #f
(at-least n sre ...)
(>= n sre ...)

More generally, n or more matches.

(regexp-search '(: "<" (>= 3 (~ #\>)) ">") "<table>")
⇒ #<regexp-match>

(regexp-search '(: "<" (>= 3 (~ #\>)) ">") "<pre>")
⇒ #<regexp-match>

(regexp-search '(: "<" (>= 3 (~ #\>)) ">") "<tr>")
⇒ #f
(exactly n sre ...)
(= n sre ...)

Exactly n matches.

(regexp-search '(: "<" (= 4 (~ #\>)) ">") "<html>")
⇒ #<regexp-match>

(regexp-search '(: "<" (= 4 (~ #\>)) ">") "<table>")
⇒ #f
(repeated from to sre ...)
(** from to sre ...)

The most general form, from n to m matches, inclusive.

(regexp-search '(: (= 3 (** 1 3 numeric) ".") (** 1 3 numeric))
               "192.168.1.10")
⇒ #<regexp-match>

(regexp-search '(: (= 3 (** 1 3 numeric) ".") (** 1 3 numeric))
               "192.0168.1.10")
⇒ #f

Next: , Previous: , Up: srfi regexps syntax   [Index]