17 Regular Expressions

▼ |  | Unstable

1 | Guidelines for developing unstable libraries
2 | Bytes
3 | Classes and Objects
4 | Contracts
5 | Definitions
6 | Dictionaries
7 | Directories
8 | Exceptions
9 | Filesystem
10 | Functions
11 | Lists
12 | Net
13 | Path
14 | PLane T Packages
15 | Ports
16 | Pretty-Printing
17 | Regular Expressions
18 | Requiring Modules
19 | Sandboxed Evaluation
20 | Scribble Documentation
21 | Sets
22 | S-Expression Diff
23 | Source Locations
24 | Strings
25 | Structs
26 | Syntax
27 | Planet Package Macros
28 | Text Representations
29 | Multiple Values
30 | XML and CSS
31 | Polymorphic Contracts
32 | Finding Mutated Variables
33 | Find
34 | Interface-Oriented Programming for Classes
35 | Sequences
36 | Hash Tables
37 | Match
38 | Generics
39 | Mark Parameters
40 | Debugging
41 | Contracts for macro subexpressions
42 | GUI libraries

On this page:

regexp-sequence
regexp-or
regexp-maybe
regexp-star
regexp-plus
regexp-save
regexp-multi

Version: 5.0.1.5
top← prev up next →

### 17`` 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

top← prev up next →