On this page:
regexp-sequence
regexp-or
regexp-maybe
regexp-star
regexp-plus
regexp-save
regexp-multi
Version: 5.0.1

18 Regular Expressions

 (require unstable/regexp)

This module provides tools for building strings which can be compiled to regular expressions. In particular, the constructors wrap their arguments in appropriate delimeters to prevent misparsing after concatenation.

(regexp-sequence [#:start start    
  #:between between    
  #:end end]    
  re ...)  string?
  start : string? = ""
  between : string? = ""
  end : string? = ""
  re : string?
Produces a regular expression string that matches start, followed by each re interleaved with between, followed by end.

Examples:

  (define re
    (pregexp
     (regexp-sequence "[0-9]+" "[0-9]+" "[0-9]+"
                      #:start (regexp-quote "(")
                      #:between (regexp-quote ",")
                      #:end (regexp-quote ")"))))
  > (regexp-match-exact? re "(1,10,100)")

  #t

  > (regexp-match-exact? re "(1,10)")

  #f

  > (regexp-match-exact? re " ( 1 , 10 , 100 ) ")

  #f

(regexp-or re ...+)  string?
  re : string?
Produces a regular expression string that matches any of the given res.

Examples:

  (define re (pregexp (regexp-or "[0-9]+" "[a-z]")))
  > (regexp-match-exact? re "123")

  #t

  > (regexp-match-exact? re "c")

  #t

  > (regexp-match-exact? re "12c")

  #f

(regexp-maybe re ...+)  string?
  re : string?
Produces a regular expression string that matches either the empty string, or the concatenation of all the given res.

Examples:

  (define re (pregexp (regexp-maybe "[0-9]+" "[.]" "[0-9]+")))
  > (regexp-match-exact? re "123.456")

  #t

  > (regexp-match-exact? re "")

  #t

  > (regexp-match-exact? re "123")

  #f

(regexp-star re ...+)  string?
  re : string?
Produces a regular expression string that matches zero or more consecutive occurrences of the concatenation of the given res.

Examples:

  (define re (pregexp (regexp-star "a" "b" "c")))
  > (regexp-match-exact? re "")

  #t

  > (regexp-match-exact? re "abc")

  #t

  > (regexp-match-exact? re "abcabcabc")

  #t

  > (regexp-match-exact? re "a")

  #f

(regexp-plus re ...+)  string?
  re : string?
Produces a regular expression string that matches one or more consecutive occurrences of the concatenation of the given res.

Examples:

  (define re (pregexp (regexp-plus "a" "b" "c")))
  > (regexp-match-exact? re "")

  #f

  > (regexp-match-exact? re "abc")

  #t

  > (regexp-match-exact? re "abcabcabc")

  #t

  > (regexp-match-exact? re "a")

  #f

(regexp-save re ...+)  string?
  re : string?
Produces a regular expression string that matches the concatenation of the given res and saves the result.

Examples:

  (define re
    (pregexp (regexp-sequence (regexp-save "[0-9]+") "\\1")))
  > (regexp-match-exact? re "11")

  #t

  > (regexp-match-exact? re "123123")

  #t

  > (regexp-match-exact? re "123456")

  #f

(regexp-multi re ...+)  string?
  re : string?
Produces a regular expression string that matches the concatenation of the given res in multiple-line mode.

Examples:

  (define re (pregexp (regexp-multi "^abc$")))
  > (regexp-match? re "abc")

  #t

  > (regexp-match? re "xyz\nabc\ndef")

  #t