# 4.6 Characters
> ```racket
> > ( string->unreadable-symbol "Apple" )
> 'Apple
> > ( eq? ' a ( string->unreadable-symbol "a" ) )
> #f
> > ( eq? ( string->unreadable-symbol "a" ) ( string->unreadable-symbol "a" ) )
> #t
> ```
> ```
(parameter)	→
(-> or/c string? symbol?)
```
(parameter)	→
(-> require racket/symbol)```

Like [symbol->string](#%28def._%28%28quote._~23~25kernel%29._symbol-~3estring%29%29), but the result is an immutable string, not necessarily freshly allocated.

Examples:

> ```racket
> > ( symbol->immutable-string ' Apple )
> "Apple"
> > ( immutable? ( symbol->immutable-string ' Apple ) )
> #t
> ```

Added in version 7.6 of package base.

------------------------------------------------------------------------

# 4.8 Regular Expressions

### 4.8 Regular Expressions

> > > <img src="finger.png" width="24" height="24" alt="+" />[Regular Expressions](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=regexp.html&version=8.18.0.13) in [The Racket Guide](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=index.html&version=8.18.0.13) introduces regular expressions.

Regular expressions are specified as strings or byte strings, using the same pattern language as either the Unix utility egrep or Perl. A string-specified pattern produces a character regexp matcher, and a byte-string pattern produces a byte regexp matcher. If a character regexp is used with a byte string or input port, it matches UTF-8 encodings (see [Encodings and Locales](encodings.html)) of matching character streams; if a byte regexp is used with a character string, it matches bytes in the UTF-8 encoding of the string.

A regular expression that is represented as a string or byte string can be compiled to a regexp value, which can be used more efficiently by functions such as [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29) compared to the string or byte string form. The [regexp](#%28def._%28%28quote._~23~25kernel%29._regexp%29%29) and [byte-regexp](#%28def._%28%28quote._~23~25kernel%29._byte-regexp%29%29) procedures convert a string or byte string (respectively) into a regexp value using a syntax of regular expressions that is most compatible to egrep. The [pregexp](#%28def._%28%28quote._~23~25kernel%29._pregexp%29%29) and [byte-pregexp](#%28def._%28%28quote._~23~25kernel%29._byte-pregexp%29%29) procedures produce a regexp value using a slightly different syntax of regular expressions that is more compatible with Perl.

Two [regexp values](#%28tech._regexp._value%29) are [equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) if they have the same source, use the same pattern language, and are both character regexps or both byte regexps.

A literal or printed [regexp value](#%28tech._regexp._value%29) starts with #rx or #px. See [Reading Regular Expressions](reader.html#%28part._parse-regexp%29) for information on [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29)ing regular expressions and [Printing Regular Expressions](printing.html#%28part._print-regexp%29) for information on [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29)ing regular expressions. Regexp values produced by the default reader are [interned](reader.html#%28tech._interned%29) in [read-syntax](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-syntax%29%29) mode.

On the [BC](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=performance.html%23%2528tech._bc%2529&version=8.18.0.13) variant of Racket, the internal size of a [regexp value](#%28tech._regexp._value%29) is limited to 32 kilobytes; this limit roughly corresponds to a source string with 32,000 literal characters or 5,000 operators.

#### 4.8.1 Regexp Syntax

The following syntax specifications describe the content of a string that represents a regular expression. The syntax of the corresponding string may involve extra escape characters. For example, the regular expression (.\*)\\1 can be represented with the string "(.\*)\\\\1" or the regexp constant #rx"(.\*)\\\\1"; the \\ in the regular expression must be escaped to include it in a string or regexp constant.

The [regexp](#%28def._%28%28quote._~23~25kernel%29._regexp%29%29) and [pregexp](#%28def._%28%28quote._~23~25kernel%29._pregexp%29%29) syntaxes share a common core:

|     |          |       |                        |     |                                              |                                      |
|:----|:---------|:-----:|:-----------------------|:----|:---------------------------------------------|:-------------------------------------|
|     | ‹regexp› |  ::=  | ‹pces›                 |     | Match ‹pces›                                 |                                      |
|     |          |  \|   | ‹regexp›\|‹regexp›     |     | Match either ‹regexp›, try left first        |  [ex1](#%28elem._%28rxex._1%29%29)   |
|     | ‹pces›   |  ::=  |                        |     | Match empty                                  |                                      |
|     |          |  \|   | ‹pce›‹pces›            |     | Match ‹pce› followed by ‹pces›               |                                      |
|     | ‹pce›    |  ::=  | ‹repeat›               |     | Match ‹repeat›, longest possible             |  [ex3](#%28elem._%28rxex._3%29%29)   |
|     |          |  \|   | ‹repeat›?              |     | Match ‹repeat›, shortest possible            |  [ex6](#%28elem._%28rxex._6%29%29)   |
|     |          |  \|   | ‹atom›                 |     | Match ‹atom› exactly once                    |                                      |
|     | ‹repeat› |  ::=  | ‹atom›\*               |     | Match ‹atom› 0 or more times                 |  [ex3](#%28elem._%28rxex._3%29%29)   |
|     |          |  \|   | ‹atom›+                |     | Match ‹atom› 1 or more times                 |  [ex4](#%28elem._%28rxex._4%29%29)   |
|     |          |  \|   | ‹atom›?                |     | Match ‹atom› 0 or 1 times                    |  [ex5](#%28elem._%28rxex._5%29%29)   |
|     | ‹atom›   |  ::=  | (‹regexp›)             |     | Match sub-expression ‹regexp› and report     |  [ex11](#%28elem._%28rxex._11%29%29) |
|     |          |  \|   | \[‹rng›\]              |     | Match any character in ‹rng›                 |  [ex2](#%28elem._%28rxex._2%29%29)   |
|     |          |  \|   | \[^‹crng›\]            |     | Match any character not in ‹crng›            |  [ex12](#%28elem._%28rxex._12%29%29) |
|     |          |  \|   | .                      |     | Match any (except newline in multi mode)     |  [ex13](#%28elem._%28rxex._13%29%29) |
|     |          |  \|   | ^                      |     | Match start (or after newline in multi mode) |  [ex14](#%28elem._%28rxex._14%29%29) |
|     |          |  \|   | $                      |     | Match end (or before newline in multi mode)  |  [ex15](#%28elem._%28rxex._15%29%29) |
|     |          |  \|   | ‹literal›              |     | Match a single literal character             |  [ex1](#%28elem._%28rxex._1%29%29)   |
|     |          |  \|   | (?‹mode›:‹regexp›)     |     | Match ‹regexp› using ‹mode›                  |  [ex35](#%28elem._%28rxex._35%29%29) |
|     |          |  \|   | (?>‹regexp›)           |     | Match ‹regexp›, only first possible          |                                      |
|     |          |  \|   | ‹look›                 |     | Match empty if ‹look› matches                |                                      |
|     |          |  \|   | (?‹tst›‹pces›\|‹pces›) |     | Match 1st ‹pces› if ‹tst›, else 2nd ‹pces›   |  [ex36](#%28elem._%28rxex._36%29%29) |
|     |          |  \|   | (?‹tst›‹pces›)         |     | Match ‹pces› if ‹tst›, empty if not ‹tst›    |                                      |
|     |          |  \|   | \\ at end of pattern   |     | Match the nul character (ASCII 0)            |                                      |
|     | ‹crng›   |  ::=  | ‹rng›                  |     | ‹crng› contains everything in ‹rng›          |                                      |
|     |          |  \|   | ^‹crng›                |     | ‹crng› contains ^ and everything in ‹crng›   |  [ex37](#%28elem._%28rxex._37%29%29) |
|     | ‹rng›    |  ::=  | \]                     |     | ‹rng› contains \] only                       |  [ex27](#%28elem._%28rxex._27%29%29) |
|     |          |  \|   | \-                     |     | ‹rng› contains - only                        |  [ex28](#%28elem._%28rxex._28%29%29) |
|     |          |  \|   | ‹mrng›                 |     | ‹rng› contains everything in ‹mrng›          |                                      |
|     |          |  \|   | ‹mrng›-                |     | ‹rng› contains - and everything in ‹mrng›    |                                      |
|     | ‹mrng›   |  ::=  | \]‹lrng›               |     | ‹mrng› contains \] and everything in ‹lrng›  |  [ex29](#%28elem._%28rxex._29%29%29) |
|     |          |  \|   | -‹lrng›                |     | ‹mrng› contains - and everything in ‹lrng›   |  [ex29](#%28elem._%28rxex._29%29%29) |
|     |          |  \|   | ‹lirng›                |     | ‹mrng› contains everything in ‹lirng›        |                                      |
|     | ‹lirng›  |  ::=  | ‹riliteral›            |     | ‹lirng› contains a literal character         |                                      |
|     |          |  \|   | ‹riliteral›-‹rliteral› |     | ‹lirng› contains Unicode range inclusive     |  [ex22](#%28elem._%28rxex._22%29%29) |
|     |          |  \|   | ‹lirng›‹lrng›          |     | ‹lirng› contains everything in both          |                                      |
|     | ‹lrng›   |  ::=  | ^                      |     | ‹lrng› contains ^                            |  [ex30](#%28elem._%28rxex._30%29%29) |
|     |          |  \|   | ‹rliteral›-‹rliteral›  |     | ‹lrng› contains Unicode range inclusive      |                                      |
|     |          |  \|   | ^‹lrng›                |     | ‹lrng› contains ^ and more                   |                                      |
|     |          |  \|   | ‹lirng›                |     | ‹lrng› contains everything in ‹lirng›        |                                      |
|     | ‹look›   |  ::=  | (?=‹regexp›)           |     | Match if ‹regexp› matches                    |  [ex31](#%28elem._%28rxex._31%29%29) |
|     |          |  \|   | (?!‹regexp›)           |     | Match if ‹regexp› doesn’t match              |  [ex32](#%28elem._%28rxex._32%29%29) |
|     |          |  \|   | (?\<=‹regexp›)         |     | Match if ‹regexp› matches preceding          |  [ex33](#%28elem._%28rxex._33%29%29) |
|     |          |  \|   | (?\<!‹regexp›)         |     | Match if ‹regexp› doesn’t match preceding    |  [ex34](#%28elem._%28rxex._34%29%29) |
|     | ‹tst›    |  ::=  | (‹n›)                  |     | True if ‹n›th ( has a match                  |                                      |
|     |          |  \|   | ‹look›                 |     | True if ‹look› matches                       |  [ex36](#%28elem._%28rxex._36%29%29) |
|     | ‹mode›   |  ::=  |                        |     | Like the enclosing mode                      |                                      |
|     |          |  \|   | ‹mode›i                |     | Like ‹mode›, but case-insensitive            |  [ex35](#%28elem._%28rxex._35%29%29) |
|     |          |  \|   | ‹mode›-i               |     | Like ‹mode›, but sensitive                   |                                      |
|     |          |  \|   | ‹mode›s                |     | Like ‹mode›, but not in multi mode           |                                      |
|     |          |  \|   | ‹mode›-s               |     | Like ‹mode›, but in multi mode               |                                      |
|     |          |  \|   | ‹mode›m                |     | Like ‹mode›, but in multi mode               |                                      |
|     |          |  \|   | ‹mode›-m               |     | Like ‹mode›, but not in multi mode           |                                      |

The following completes the grammar for [regexp](#%28def._%28%28quote._~23~25kernel%29._regexp%29%29), which treats { and } as literals, \\ as a literal within ranges, and \\ as a literal producer outside of ranges.

|     |             |       |                                                          |     |                  |                                      |
|:----|:------------|:-----:|:---------------------------------------------------------|:----|:-----------------|:-------------------------------------|
|     | ‹literal›   |  ::=  | Any character except (, ), \*, +, ?, \[, ., ^, \\, or \| |     |                  |                                      |
|     |             |  \|   | \\‹aliteral›                                             |     | Match ‹aliteral› |  [ex21](#%28elem._%28rxex._21%29%29) |
|     | ‹aliteral›  |  ::=  | Any character                                            |     |                  |                                      |
|     | ‹riliteral› |  ::=  | Any character except \], -, or ^                         |     |                  |                                      |
|     | ‹rliteral›  |  ::=  | Any character except \] or -                             |     |                  |                                      |

The following completes the grammar for [pregexp](#%28def._%28%28quote._~23~25kernel%29._pregexp%29%29), which uses { and } bounded repetition and uses \\ for meta-characters both inside and outside of ranges.

|     |             |       |                                                                    |     |                                                 |                                      |
|:----|:------------|:-----:|:-------------------------------------------------------------------|:----|:------------------------------------------------|:-------------------------------------|
|     | ‹repeat›    |  ::=  | ...                                                                |     | ...                                             |                                      |
|     |             |  \|   | ‹atom›{‹n›}                                                        |     | Match ‹atom› exactly ‹n› times                  |  [ex7](#%28elem._%28rxex._7%29%29)   |
|     |             |  \|   | ‹atom›{‹n›,}                                                       |     | Match ‹atom› ‹n› or more times                  |  [ex8](#%28elem._%28rxex._8%29%29)   |
|     |             |  \|   | ‹atom›{,‹m›}                                                       |     | Match ‹atom› between 0 and ‹m› times            |  [ex9](#%28elem._%28rxex._9%29%29)   |
|     |             |  \|   | ‹atom›{‹n›,‹m›}                                                    |     | Match ‹atom› between ‹n› and ‹m› times          |  [ex10](#%28elem._%28rxex._10%29%29) |
|     |             |  \|   | ‹atom›{}                                                           |     | Match ‹atom› 0 or more times                    |                                      |
|     | ‹atom›      |  ::=  | ...                                                                |     | ...                                             |                                      |
|     |             |  \|   | \\‹n›                                                              |     | Match latest reported match for ‹n›th (         |  [ex16](#%28elem._%28rxex._16%29%29) |
|     |             |  \|   | ‹class›                                                            |     | Match any character in ‹class›                  |                                      |
|     |             |  \|   | \\b                                                                |     | Match \\w\* boundary                            |  [ex17](#%28elem._%28rxex._17%29%29) |
|     |             |  \|   | \\B                                                                |     | Match where \\b does not                        |  [ex18](#%28elem._%28rxex._18%29%29) |
|     |             |  \|   | \\p{‹property›}                                                    |     | Match (UTF-8 encoded) in ‹property›             |  [ex19](#%28elem._%28rxex._19%29%29) |
|     |             |  \|   | \\P{‹property›}                                                    |     | Match (UTF-8 encoded) not in ‹property›         |  [ex20](#%28elem._%28rxex._20%29%29) |
|     |             |  \|   | \\X                                                                |     | Match (UTF-8 encoded) grapheme cluster          |                                      |
|     | ‹literal›   |  ::=  | Any character except (, ), \*, +, ?, \[, \], {, }, ., ^, \\, or \| |     |                                                 |                                      |
|     |             |  \|   | \\‹aliteral›                                                       |     | Match ‹aliteral›                                |  [ex21](#%28elem._%28rxex._21%29%29) |
|     | ‹aliteral›  |  ::=  | Any character except a-z, A-Z, 0-9                                 |     |                                                 |                                      |
|     | ‹lirng›     |  ::=  | ...                                                                |     | ...                                             |                                      |
|     |             |  \|   | ‹class›                                                            |     | ‹lirng› contains all characters in ‹class›      |                                      |
|     |             |  \|   | ‹posix›                                                            |     | ‹lirng› contains all characters in ‹posix›      |  [ex26](#%28elem._%28rxex._26%29%29) |
|     |             |  \|   | \\‹eliteral›                                                       |     | ‹lirng› contains ‹eliteral›                     |                                      |
|     | ‹riliteral› |  ::=  | Any character except \], \\, -, or ^                               |     |                                                 |                                      |
|     | ‹rliteral›  |  ::=  | Any character except \], \\, or -                                  |     |                                                 |                                      |
|     | ‹eliteral›  |  ::=  | Any character except a-z, A-Z                                      |     |                                                 |                                      |
|     | ‹class›     |  ::=  | \\d                                                                |     | Contains 0-9                                    |  [ex23](#%28elem._%28rxex._23%29%29) |
|     |             |  \|   | \\D                                                                |     | Contains characters not in \\d                  |                                      |
|     |             |  \|   | \\w                                                                |     | Contains a-z, A-Z, 0-9, \_                      |  [ex24](#%28elem._%28rxex._24%29%29) |
|     |             |  \|   | \\W                                                                |     | Contains characters not in \\w                  |                                      |
|     |             |  \|   | \\s                                                                |     | Contains space, tab, newline, formfeed, return  |  [ex25](#%28elem._%28rxex._25%29%29) |
|     |             |  \|   | \\S                                                                |     | Contains characters not in \\s                  |                                      |
|     | ‹posix›     |  ::=  | \[:alpha:\]                                                        |     | Contains a-z, A-Z                               |                                      |
|     |             |  \|   | \[:upper:\]                                                        |     | Contains A-Z                                    |                                      |
|     |             |  \|   | \[:lower:\]                                                        |     | Contains a-z                                    |  [ex26](#%28elem._%28rxex._26%29%29) |
|     |             |  \|   | \[:digit:\]                                                        |     | Contains 0-9                                    |                                      |
|     |             |  \|   | \[:xdigit:\]                                                       |     | Contains 0-9, a-f, A-F                          |                                      |
|     |             |  \|   | \[:alnum:\]                                                        |     | Contains a-z, A-Z, 0-9                          |                                      |
|     |             |  \|   | \[:word:\]                                                         |     | Contains a-z, A-Z, 0-9, \_                      |                                      |
|     |             |  \|   | \[:blank:\]                                                        |     | Contains space and tab                          |                                      |
|     |             |  \|   | \[:space:\]                                                        |     | Contains space, tab, newline, formfeed, return  |                                      |
|     |             |  \|   | \[:graph:\]                                                        |     | Contains all ASCII characters that use ink      |                                      |
|     |             |  \|   | \[:print:\]                                                        |     | Contains space, tab, and ASCII ink users        |                                      |
|     |             |  \|   | \[:cntrl:\]                                                        |     | Contains all characters with scalar value \< 32 |                                      |
|     |             |  \|   | \[:ascii:\]                                                        |     | Contains all ASCII characters                   |                                      |
|     | ‹property›  |  ::=  | ‹category›                                                         |     | Includes all characters in ‹category›           |                                      |
|     |             |  \|   | ^‹category›                                                        |     | Includes all characters not in ‹category›       |                                      |

In case-insensitive mode, a backreference of the form \\‹n› matches case-insensitively only with respect to ASCII characters.

The Unicode categories follow.

|     |            |       |     |     |                                         |                                      |
|:----|:-----------|:-----:|:----|:----|:----------------------------------------|:-------------------------------------|
|     | ‹category› |  ::=  | Ll  |     | Letter, lowercase                       |  [ex19](#%28elem._%28rxex._19%29%29) |
|     |            |  \|   | Lu  |     | Letter, uppercase                       |                                      |
|     |            |  \|   | Lt  |     | Letter, titlecase                       |                                      |
|     |            |  \|   | Lm  |     | Letter, modifier                        |                                      |
|     |            |  \|   | L&  |     | Union of Ll, Lu, Lt, and Lm             |                                      |
|     |            |  \|   | Lo  |     | Letter, other                           |                                      |
|     |            |  \|   | L   |     | Union of L& and Lo                      |                                      |
|     |            |  \|   | Nd  |     | Number, decimal digit                   |                                      |
|     |            |  \|   | Nl  |     | Number, letter                          |                                      |
|     |            |  \|   | No  |     | Number, other                           |                                      |
|     |            |  \|   | N   |     | Union of Nd, Nl, and No                 |                                      |
|     |            |  \|   | Ps  |     | Punctuation, open                       |                                      |
|     |            |  \|   | Pe  |     | Punctuation, close                      |                                      |
|     |            |  \|   | Pi  |     | Punctuation, initial quote              |                                      |
|     |            |  \|   | Pf  |     | Punctuation, final quote                |                                      |
|     |            |  \|   | Pc  |     | Punctuation, connector                  |                                      |
|     |            |  \|   | Pd  |     | Punctuation, dash                       |                                      |
|     |            |  \|   | Po  |     | Punctuation, other                      |                                      |
|     |            |  \|   | P   |     | Union of Ps, Pe, Pi, Pf, Pc, Pd, and Po |                                      |
|     |            |  \|   | Mn  |     | Mark, non-spacing                       |                                      |
|     |            |  \|   | Mc  |     | Mark, spacing combining                 |                                      |
|     |            |  \|   | Me  |     | Mark, enclosing                         |                                      |
|     |            |  \|   | M   |     | Union of Mn, Mc, and Me                 |                                      |
|     |            |  \|   | Sc  |     | Symbol, currency                        |                                      |
|     |            |  \|   | Sk  |     | Symbol, modifier                        |                                      |
|     |            |  \|   | Sm  |     | Symbol, math                            |                                      |
|     |            |  \|   | So  |     | Symbol, other                           |                                      |
|     |            |  \|   | S   |     | Union of Sc, Sk, Sm, and So             |                                      |
|     |            |  \|   | Zl  |     | Separator, line                         |                                      |
|     |            |  \|   | Zp  |     | Separator, paragraph                    |                                      |
|     |            |  \|   | Zs  |     | Separator, space                        |                                      |
|     |            |  \|   | Z   |     | Union of Zl, Zp, and Zs                 |                                      |
|     |            |  \|   | Cc  |     | Other, control                          |                                      |
|     |            |  \|   | Cf  |     | Other, format                           |                                      |
|     |            |  \|   | Cs  |     | Other, surrogate                        |                                      |
|     |            |  \|   | Cn  |     | Other, not assigned                     |                                      |
|     |            |  \|   | Co  |     | Other, private use                      |                                      |
|     |            |  \|   | C   |     | Union of Cc, Cf, Cs, Cn, and Co         |                                      |
|     |            |  \|   | .   |     | Union of all Unicode categories         |                                      |

When a character regexp with . is used with a byte string or input port, the . matches only a valid UTF-8 encoding in the input. A . in a byte regexp matches any byte (except a newline in multi mode). A property specified with \\P or \\p matches only a valid UTF-8 encoding, whether it is written in a character regexp or byte regexp. Similarly, \\X matches only valid UTF-8 encoding sequences, and it will not match a prefix of a sequence (even if matching only a prefix would allow the rest of the pattern to match remaining input), but a grapheme-cluster sequence can be terminated by an invalid UTF-8 encoding.

Examples:

> ```racket
> > ( regexp-match #rx"a|b" "cat" ) ; ex 1
> '("a")
> > ( regexp-match #rx"[at]" "cat" ) ; ex 2
> '("a")
> > ( regexp-match #rx"ca*[at]" "caaat" ) ; ex 3
> '("caaat")
> > ( regexp-match #rx"ca+[at]" "caaat" ) ; ex 4
> '("caaat")
> > ( regexp-match #rx"ca?t?" "ct" ) ; ex 5
> '("ct")
> > ( regexp-match #rx"ca*?[at]" "caaat" ) ; ex 6
> '("ca")
> > ( regexp-match #px"ca{2}" "caaat" ) ; ex 7 , uses #px
> '("caa")
> > ( regexp-match #px"ca{2,}t" "catcaat" ) ; ex 8 , uses #px
> '("caat")
> > ( regexp-match #px"ca{,2}t" "caaatcat" ) ; ex 9 , uses #px
> '("cat")
> > ( regexp-match #px"ca{1,2}t" "caaatcat" ) ; ex 10 , uses #px
> '("cat")
> > ( regexp-match #rx"(c<*)(a*)" "caat" ) ; ex 11> '("caa" "c" "aa")
> > ( regexp-match #rx"[^ca]" "caat" ) ; ex 12
> '("t")
> > ( regexp-match #rx".(.)." "cat" ) ; ex 13
> '("cat" "a")
> > ( regexp-match #rx"^a|^c" "cat" ) ; ex 14
> '("c")
> > ( regexp-match #rx"a$|t$" "cat" ) ; ex 15
> '("t")
> > ( regexp-match #px"c(.)\\1t" "caat" ) ; ex 16 , uses #px
> '("caat" "a")
> > ( regexp-match #px".\\b." "cat in hat" ) ; ex 17 , uses #px
> '("t ")
> > ( regexp-match #px".\\B." "cat in hat" ) ; ex 18 , uses #px
> '("ca")
> > ( regexp-match #px"\\p{Ll}" "Cat" ) ; ex 19 , uses #px
> '("a")
> > ( regexp-match #px"\\P{Ll}" "cat!" ) ; ex 20 , uses #px
> '("!")
> > ( regexp-match #rx"\\|" "c|t" ) ; ex 21
> '("|")
> > ( regexp-match #rx"[a-f]*" "cat" ) ; ex 22
> '("ca")
> > ( regexp-match #px"[a-f\\d]*" "1cat" ) ; ex 23 , uses #px
> '("1ca")
> > ( regexp-match #px" [\\w]" "cat hat" ) ; ex 24 , uses #px
> '(" h")
> > ( regexp-match #px"t[\\s]" "cat\nhat" ) ; ex 25 , uses #px
> '("t\n")
> > ( regexp-match #px"[[:lower:]]+" "Cat" ) ; ex 26 , uses #px
> '("at")
> > ( regexp-match #rx"[]]" "c]t" ) ; ex 27
> '("]")
> > ( regexp-match #rx"[-]" "c-t" ) ; ex 28
> '("-")
> > ( regexp-match #rx"[]a[]+" "c[a]t" ) ; ex 29
> '("[a]")
> > ( regexp-match #rx"[a^]+" "ca^t" ) ; ex 30
> '("a^")
> > ( regexp-match #rx".a(?=p)" "cat nap" ) ; ex 31
> '("na")
> > ( regexp-match #rx".a(?!t)" "cat nap" ) ; ex 32
> '("na")
> > ( regexp-match #rx"(?<=n)a." "cat nap" ) ; ex 33> '("ap")
> > ( regexp-match #rx"(?<!c)a." "cat nap" ) ; ex 34> '("ap")
> > ( regexp-match #rx"(?i:a)[tp]" "cAT nAp" ) ; ex 35
> '("Ap")
> > ( regexp-match #rx"(?(?<=c)a|b)+" "cabal" ) ; ex 36> '("ab")
> > ( regexp-match #rx"[^^]+" "^cat^" ) ; ex 37
> '("cat")
> ```

Changed in version 8.15.0.8 of package base: Added \\X grapheme cluster pattern.

#### 4.8.2 Additional Syntactic Constraints

In addition to matching a grammar, regular expressions must meet two syntactic restrictions:

-   In a ‹repeat› other than ‹atom›?, the ‹atom› must not match an empty sequence.

-   In a (?\<=‹regexp›) or (?\<!‹regexp›), the ‹regexp› must match a bounded sequence only.

These constraints are checked syntactically by the following type system. A type \[n, m\] corresponds to an expression that matches between n and m characters. In the rule for (‹regexp›), ‹n› means the number such that the opening parenthesis is the ‹n›th opening parenthesis for collecting match reports. Non-emptiness is inferred for a backreference pattern, \\‹n›, so that a backreference can be used for repetition patterns; in the case of mutual dependencies among backreferences, the inference chooses the fixpoint that maximizes non-emptiness. Finiteness is not inferred for backreferences (i.e., a backreference is assumed to match an arbitrarily large sequence). No syntactic constraint prohibits a backreference within the group that it references, although such self references might create a pattern with no possible matches (as in the case of (.\\1), although (^.\|\\1){2} matches an input that starts with the same two characters).

<table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp›1 : [n1, m1]   ‹regexp›2 : [n2, m2] </p></td></tr><tr><td style="text-align: center;"><p> ‹regexp›1|‹regexp›2 : [min(n1, n2), max(m1, m2)] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹pce› : [n1, m1]   ‹pces› : [n2, m2] </p></td></tr><tr><td style="text-align: center;"><p> ‹pce›‹pces› : [n1+n2, m1+m2] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 33%" /><col style="width: 33%" /><col style="width: 33%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹repeat› : [n, m] </p></td></tr><tr><td style="text-align: center;"><p> ‹repeat›? : [0, m] </p></td></tr></tbody></table></td><td><p>   </p></td><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹atom› : [n, m]   n > 0 </p></td></tr><tr><td style="text-align: center;"><p> ‹atom›* : [0, ∞] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 33%" /><col style="width: 33%" /><col style="width: 33%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹atom› : [n, m]   n > 0 </p></td></tr><tr><td style="text-align: center;"><p> ‹atom›+ : [1, ∞] </p></td></tr></tbody></table></td><td><p>   </p></td><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹atom› : [n, m] </p></td></tr><tr><td style="text-align: center;"><p> ‹atom›? : [0, m] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹atom› : [n, m]   n > 0 </p></td></tr><tr><td style="text-align: center;"><p> ‹atom›{‹n›} : [n*‹n›, m*‹n›] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹atom› : [n, m]   n > 0 </p></td></tr><tr><td style="text-align: center;"><p> ‹atom›{‹n›,} : [n*‹n›, ∞] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹atom› : [n, m]   n > 0 </p></td></tr><tr><td style="text-align: center;"><p> ‹atom›{,‹m›} : [0, m*‹m›] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹atom› : [n, m]   n > 0 </p></td></tr><tr><td style="text-align: center;"><p> ‹atom›{‹n›,‹m›} : [n*‹n›, m*‹m›] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp› : [n, m] </p></td></tr><tr><td style="text-align: center;"><p> (‹regexp›) : [n, m]   α‹n›=n </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp› : [n, m] </p></td></tr><tr><td style="text-align: center;"><p> (?‹mode›:‹regexp›) : [n, m] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 33%" /><col style="width: 33%" /><col style="width: 33%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp› : [n, m] </p></td></tr><tr><td style="text-align: center;"><p> (?=‹regexp›) : [0, 0] </p></td></tr></tbody></table></td><td><p>   </p></td><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp› : [n, m] </p></td></tr><tr><td style="text-align: center;"><p> (?!‹regexp›) : [0, 0] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 33%" /><col style="width: 33%" /><col style="width: 33%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp› : [n, m]   m < ∞ </p></td></tr><tr><td style="text-align: center;"><p> (?<=‹regexp›) : [0, 0] </p></td></tr></tbody></table></td><td><p>   </p></td><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp› : [n, m]   m < ∞ </p></td></tr><tr><td style="text-align: center;"><p> (?<!‹regexp›) : [0, 0] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹regexp› : [n, m] </p></td></tr><tr><td style="text-align: center;"><p> (?>‹regexp›) : [n, m] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹tst› : [n0, m0]   ‹pces›1 : [n1, m1]   ‹pces›2 : [n2, m2] </p></td></tr><tr><td style="text-align: center;"><p> (?‹tst›‹pces›1|‹pces›2) : [min(n1, n2), max(m1, m2)] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td style="text-align: center;"><p> ‹tst› : [n0, m0]   ‹pces› : [n1, m1] </p></td></tr><tr><td style="text-align: center;"><p> (?‹tst›‹pces›) : [0, m1] </p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td><p>(‹n›) : [α‹n›, ∞]</p></td><td><p>   </p></td><td><p>[‹rng›] : [1, 1]</p></td><td><p>   </p></td><td><p>[^‹rng›] : [1, 1]</p></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td><p>. : [1, 1]</p></td><td><p>   </p></td><td><p>^ : [0, 0]</p></td><td><p>   </p></td><td><p>$ : [0, 0]</p></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td><p>‹literal› : [1, 1]</p></td><td><p>   </p></td><td><p>\‹n› : [α‹n›, ∞]</p></td><td><p>   </p></td><td><p>‹class› : [1, 1]</p></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td><p>\b : [0, 0]</p></td><td><p>   </p></td><td><p>\B : [0, 0]</p></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td><p>\p{‹property›} : [1, 6]</p></td><td><p>   </p></td><td><p>\P{‹property›} : [1, 6]</p></td></tr></tbody></table></td></tr><tr><td style="text-align: center;"><p> </p></td></tr><tr><td style="text-align: center;"><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td><p>\X : [1, ∞]</p></td></tr></tbody></table></td></tr></tbody></table>

#### 4.8.3 Regexp Constructors

> ```
(regexp? v)  →  boolean?
  v : any/c
```


# 4.6 Characters
Returns #t if v is a regexp value created by regexp or pregexp, #f otherwise.
> ```
(pregexp? v)   →   boolean?
  v : any/c```
Returns #t if v is a [regexp value](#%28tech._regexp._value%29) created by [pregexp](#%28def._%28%28quote._~23~25kernel%29._pregexp%29%29) (not [regexp](#%28def._%28%28quote._~23~25kernel%29._regexp%29%29)), #f otherwise.
> ```
(byte-regexp? v)  →  boolean?
  v : any/c
```
Returns #t if v is a regexp value created by byte-regexp or byte-pregexp, #f otherwise.

> ```
(byte-pregexp? v)   →   boolean?
  v : any/c```

Returns #t if v is a [regexp value](#%28tech._regexp._value%29) created by [byte-pregexp](#%28def._%28%28quote._~23~25kernel%29._byte-pregexp%29%29) (not [byte-regexp](#%28def._%28%28quote._~23~25kernel%29._byte-regexp%29%29)), #f otherwise.

> ```
(regexp str)  →  regexp?
  str : string?
(regexp str handler)  →  any
  str : string?
  handler : (or/c #f (string? .  →  . any))
```
Takes a string representation of a regular expression (using the syntax in Regexp Syntax) and compiles it into a regexp value. Other regular expression procedures accept either a string or a regexp value as the matching pattern. If a regular expression string is used multiple times, it is faster to compile the string once to a regexp value and use it for repeated matches instead of using the string each time.


# 4.6 Characters
If handler is provided and not #f, it is called and its result is returned when str is not a valid representation of a regular expression; the argument to handler is a string that describes the problem with str. If handler is #f or not provided, then exn:fail:contract exception is raised.
The object-name procedure returns the source string for a regexp value.
Examples:
> ```racket
> > ( regexp "ap*le" )
> #rx"ap*le"
> > ( object-name #rx"ap*le" )
> "ap*le"
> > ( regexp "+" ( λ ( s ) ( list s ) ) )
> '("`+` follows nothing in pattern")
> ```
Changed in version 6.5.0.1 of package base: Added the handler argument.
> ```
(pregexp str)   →   pregexp?
  str : string?
(pregexp str handler)   →   any
  str : string?
  handler : (or/c #f (string? .  →  . any))```
Like [regexp](#%28def._%28%28quote._~23~25kernel%29._regexp%29%29), except that it uses a slightly different syntax (see [Regexp Syntax](#%28part._regexp-syntax%29)). The result can be used with [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29), etc., just like the result from [regexp](#%28def._%28%28quote._~23~25kernel%29._regexp%29%29).
Examples:
> ```racket
> > ( pregexp "ap*le" )
> #px"ap*le"
> > ( regexp? #px"ap*le" )
> #t
> > ( pregexp "+" ( λ ( s ) ( vector s ) ) )
> '#("`+` follows nothing in pattern")
> ```
Changed in version 6.5.0.1 of package base: Added the handler argument.
> ```
(byte-regexp bstr)  →  byte-regexp?
  bstr : bytes?
(byte-regexp bstr handler)  →  any
  bstr : bytes?
  handler : (or/c #f (bytes? .  →  . any))


# 4.6 Characters
```
Takes a byte-string representation of a regular expression (using the syntax in Regexp Syntax) and compiles it into a byte-regexp value.

If handler is provided, it is called and its result is returned if bstr is not a valid representation of a regular expression.

The object-name procedure returns the source byte string for a regexp value.

Examples:

> ```racket
> > ( byte-regexp #"ap*le" )
> #rx#"ap*le"
> > ( object-name #rx#"ap*le" )
> #"ap*le"
> > ( byte-regexp "ap*le" )
> byte-regexp: contract violation
> expected: bytes?
> given: "ap*le"
> > ( byte-regexp #"+" ( λ ( s ) ( list s ) ) )
> '("`+` follows nothing in pattern")
> ```

Changed in version 6.5.0.1 of package base: Added the handler argument.

> ```
(byte-pregexp bstr)   →   byte-pregexp?
  bstr : bytes?
(byte-pregexp bstr handler)   →   any
  bstr : bytes?
  handler : (or/c #f (bytes? .  →  . any))```

Like [byte-regexp](#%28def._%28%28quote._~23~25kernel%29._byte-regexp%29%29), except that it uses a slightly different syntax (see [Regexp Syntax](#%28part._regexp-syntax%29)). The result can be used with [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29), etc., just like the result from [byte-regexp](#%28def._%28%28quote._~23~25kernel%29._byte-regexp%29%29).

Examples:

> ```racket
> > ( byte-pregexp #"ap*le" )
> #px#"ap*le"
> > ( byte-pregexp #"+" ( λ ( s ) ( vector s ) ) )
> '#("`+` follows nothing in pattern")
> ```

Changed in version 6.5.0.1 of package base: Added the handler argument.

> ```
(regexp-quote str [case-sensitive?) → string?
  str : string?
  case-sensitive? : any/c = #t
(regexp-quote bstr [case-sensitive?)  →  bytes?
  bstr : bytes?
  case-sensitive? : any/c = #t
```


# 4.6 Characters
Produces a string or byte string suitable for use with regexp to match the literal sequence of characters in str or sequence of bytes in bstr. If case-sensitive? is true (the default), the resulting regexp matches letters in str or bstr case-sensitively, otherwise it matches case-insensitively.
Examples:
> ```racket
> > ( regexp-match "." "apple.scm" )
> '("a")
> > ( regexp-match ( regexp-quote "." ) "apple.scm" )
> '(".")
> ```
> ```
(pregexp-quote str [case-sensitive?) → string?
  str : string?
  case-sensitive? : any/c = #t
(pregexp-quote bstr [case-sensitive?)   →   bytes?
  bstr : bytes?
  case-sensitive? : any/c = #t```
Like [regexp-quote](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._regexp-quote%29%29), but intended for use with [pregexp](#%28def._%28%28quote._~23~25kernel%29._pregexp%29%29). Escapes all non-alphanumeric, non-underscore characters in the input.
Added in version 8.11.1.9 of package base.
> ```
(regexp-max-lookbehind pattern)  →  exact-nonnegative-integer?
  pattern : (or/c regexp? byte-regexp?)


# 4.6 Characters
```
Returns the maximum number of bytes that pattern may consult before the starting position of a match to determine the match. For example, the pattern (?\<=abc)d consults three bytes preceding a matching d, while e(?\<=a..)d consults two bytes before a matching ed. A ^ pattern may consult a preceding byte to determine whether the current position is the start of the input or of a line.

Examples:

> ```racket
> > ( regexp-max-lookbehind #rx#"(?<=abc)d" )> 3
> > ( regexp-max-lookbehind #rx#"e(?<=a..)d" )> 2
> > ( regexp-max-lookbehind #rx"^" )
> 1
> ```

> ```
(regexp-capture-group-count pattern)
   →   exact-nonnegative-integer?
  pattern : (or/c regexp? byte-regexp?)```

Returns the number of capture groups that are in pattern, which corresponds to one less than the length of the list returned by [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29) for a successful match to pattern.

Examples:

> ```racket
> > ( regexp-capture-group-count #rx"abcd" )
> 0
> > ( regexp-capture-group-count #rx"a(b*c)(d*)" )
> 2
> > ( regexp-capture-group-count #rx"a(?:bc)*d" )
> 0
> ```

Added in version 8.15.0.8 of package base.

#### 4.8.4 Regexp Matching

> ```
(regexp-match pattern
    input
   [ start-pos
    end-pos
    output-port
    input-prefix)

   →    ( if ( and ( or ( string? pattern ) ( regexp? pattern ) )
> ( or ( string? input ) ( path? input ) ) )
> ( or/c #f ( cons/c string? ( listof ( or/c string? #f ) ) ) )
> ( or/c #f ( cons/c bytes? ( listof ( or/c bytes? #f ) ) ) ) )

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? path? input-port?)
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  output-port : (or/c output-port? #f) = #f
  input-prefix : bytes? = #""
```


# 4.6 Characters
(byte)	→
(-> in the case of an input port)```
Like [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29), but the result is a list of strings or byte strings corresponding to a sequence of matches of pattern in input.
The pattern is used in order to find matches, where each match attempt starts at the end of the last match, and ^ is allowed to match the beginning of the input (if input-prefix is #"") only for the first match. Empty matches are handled like other matches, returning a zero-length string or byte sequence (they are more useful in making this a complement of [regexp-split](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._regexp-split%29%29)), but pattern is restricted from matching an empty sequence immediately after an empty match.
If input contains no matches (in the range start-pos to end-pos), [null](pairs.html#%28def._%28%28quote._~23~25kernel%29._null%29%29) is returned. Otherwise, each item in the resulting list is a distinct substring or byte sequence from input that matches pattern. The end-pos argument can be #f to match to the end of input (which corresponds to an end-of-file if input is an input port).
Examples:
> ```racket
> > ( regexp-match* #rx"x." "12x4x6" )
> '("x4" "x6")
> > ( regexp-match* #rx"x*" "12x4x6" )
> '("" "" "x" "" "x" "" "")
> ```


# 4.6 Characters
The match-select function specifies the collected results. The default of [car](pairs.html#%28def._%28%28quote._~23~25kernel%29._car%29%29) means that the result is the list of matches without returning parenthesized sub-patterns. It can be given as a “selector” function which chooses an item from a list, or it can choose a list of items. For example, you can use [cdr](pairs.html#%28def._%28%28quote._~23~25kernel%29._cdr%29%29) to get a list of lists of parenthesized sub-patterns matches, or [values](values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29) (as an identity function) to get the full matches as well. (Note that the selector must choose an element of its input list or a list of elements, but it must not inspect its input as they can be either a list of strings or a list of position pairs. Furthermore, the selector must be consistent in its choice(s).)
Examples:
> ```racket
> > ( regexp-match* #rx"x(.)" "12x4x6" #:match-select cadr )
> '("4" "6")
> > ( regexp-match* #rx"x(.)" "12x4x6" #:match-select values )
> '(("x4" "4") ("x6" "6"))
> ```
In addition, specifying gap-select as a non-#f value will make the result an interleaved list of the matches as well as the separators between them matches, starting and ending with a separator. In this case, match-select can be given as #f to return only the separators, making such uses equivalent to [regexp-split](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._regexp-split%29%29).
Examples:


# 4.6 Characters
> ```racket
> > ( regexp-match* #rx"x(.)" "12x4x6" #:match-select cadr #:gap-select? #t )
> '("12" "4" "" "6" "")
> > ( regexp-match* #rx"x(.)" "12x4x6" #:match-select #f #:gap-select? #t )
> '("12" "" "")
> ```
> ```
(regexp-try-match pattern
    input
   [ start-pos
    end-pos
    output-port
    input-prefix)
  →  (or/c #f (cons/c bytes? (listof (or/c bytes? #f))))
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  output-port : (or/c output-port? #f) = #f
  input-prefix : bytes? = #""


# 4.6 Characters
```
Like regexp-match on input ports, except that if the match fails, no characters are read and discarded from in.

This procedure is especially useful with a pattern that begins with a start-of-string ^ or with a non-#f end-pos, since each limits the amount of peeking into the port. Otherwise, beware that a large portion of the stream may be peeked (and therefore pulled into memory) before the match succeeds or fails.

> ```
(regexp-match-positions pattern
    input
   [ start-pos
    end-pos
    output-port
    input-prefix)

   →    ( or/c ( cons/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> ( listof ( or/c ( cons/c exact-integer?
> exact-integer? )
> #f ) ) )
> #f )

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? path? input-port?)
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  output-port : (or/c output-port? #f) = #f
  input-prefix : bytes? = #""```

Like [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29), but returns a list of number pairs (and #f) instead of a list of strings. Each pair of numbers refers to a range of characters or bytes in input. If the result for the same arguments with [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29) would be a list of byte strings, the resulting ranges correspond to byte ranges; in that case, if input is a character string, the byte ranges correspond to bytes in the UTF-8 encoding of the string.

Range results are returned in a [substring](strings.html#%28def._%28%28quote._~23~25kernel%29._substring%29%29)- and [subbytes](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._subbytes%29%29)-compatible manner, independent of start-pos. In the case of an input port, the returned positions indicate the number of bytes that were read, including start-pos, before the first matching byte.

Examples:

> ```racket
> > ( regexp-match-positions #rx"x." "12x4x6" )
> '((2 . 4))
> > ( regexp-match-positions #rx"x." "12x4x6" 3 )
> '((4 . 6))
> > ( regexp-match-positions #rx"(-[0-9]*)+" "a-12--345b" )
> '((1 . 9) (5 . 9))
> ```

Range results after the first one can include negative numbers if input-prefix is non-empty and if pattern includes a lookbehind pattern. Such ranges start in the input-prefix instead of input. More generally, when start-pos is positive, then range results that are less than start-pos start in input-prefix.

Examples:

> ```racket
> > ( regexp-match-positions #rx"(?<=(.))." "a" 0 #f #f #"x" )> '((0 . 1) (-1 . 0))
> > ( regexp-match-positions #rx"(?<=(..))." "a" 0 #f #f #"x" )> #f
> > ( regexp-match-positions #rx"(?<=(..))." "_a" 1 #f #f #"x" )> #f
> ```

Although input-prefix is always a byte string, when the returned positions are string indices and they refer to a portion of input-prefix, then they correspond to a UTF-8 decoding of a tail of input-prefix.

Examples:

> ```racket
> > ( bytes-length ( string->bytes/utf-8 "λ" ) )
> 2
> > ( regexp-match-positions #rx"(?<=(.))." "a" 0 #f #f ( string->bytes/utf-8 "λ" ) )
> '((0 . 1) (-1 . 0))
> ```

> ```
(regexp-match-positions* pattern
    input
   [ start-pos
    end-pos
    input-prefix
    #:match-select match-select)

   →    ( or/c ( listof ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? ) )
> ( listof ( listof ( or/c #f ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? ) ) ) ) )

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? path? input-port?)
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  input-prefix : bytes? = #""
  match-select : (list? .  →  . (or/c any/c list?)) = car
```


# 4.6 Characters
Like regexp-match-positions, but returns multiple matches like regexp-match*.
Examples:
> ```racket
> > ( regexp-match-positions* #rx"x." "12x4x6" )
> '((2 . 4) (4 . 6))
> > ( regexp-match-positions* #rx"x(.)" "12x4x6" #:match-select cadr )
> '((3 . 4) (5 . 6))
> ```
Note that unlike regexp-match*, there is no #:gap-select? input keyword, as this information can be easily inferred from the resulting matches.
> ```
(regexp-match? pattern
    input
   [ start-pos
    end-pos
    output-port
    input-prefix)    →    boolean?
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? path? input-port?)
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  output-port : (or/c output-port? #f) = #f
  input-prefix : bytes? = #""```
Like [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29), but returns merely #t when the match succeeds, #f otherwise.
Examples:
> ```racket
> > ( regexp-match? #rx"x." "12x4x6" )
> #t
> > ( regexp-match? #rx"y." "12x4x6" )
> #f
> ```
> ```
(regexp-match-exact? pattern input)  →  boolean?
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? path?)


# 4.6 Characters
```
Like regexp-match?, but #t is only returned when the first found match is to the entire content of input.

Examples:

> ```racket
> > ( regexp-match-exact? #rx"x." "12x4x6" )
> #f
> > ( regexp-match-exact? #rx"1.*x." "12x4x6" )
> #t
> ```

Beware that regexp-match-exact? can return #f if pattern generates a partial match for input first, even if pattern could also generate a complete match. To check if there is any match of pattern that covers all of input, use regexp-match? with ^(?:pattern)$ instead.

Examples:

> ```racket
> > ( regexp-match-exact? #rx"a|ab" "ab" )
> #f
> > ( regexp-match? #rx"^(?:a|ab)$" "ab" )
> #t
> ```

The (?:) grouping is necessary because concatenation has lower precedence than alternation; the regular expression without it, ^a\|ab$, matches any input that either starts with a or ends with ab.

Example:

> ```racket
> > ( regexp-match? #rx"^a|ab$" "123ab" )
> #t
> ```

> ```
(regexp-match-peek pattern
    input
   [ start-pos
    end-pos
    progress
    input-prefix)

   →    ( or/c ( cons/c bytes? ( listof ( or/c bytes? #f ) ) )
> #f )

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  progress : (or/c progress-evt? #f) = #f
  input-prefix : bytes? = #""```

Like [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29) on input ports, but only peeks bytes from input instead of reading them. Furthermore, instead of an output port, the optional progress argument is a progress event for input (see [port-progress-evt](Byte_and_String_Input.html#%28def._%28%28quote._~23~25kernel%29._port-progress-evt%29%29)). If progress becomes ready, then the match stops peeking from input and returns #f. The progress argument can be #f, in which case the peek may continue with inconsistent information if another process meanwhile reads from input.

Examples:

> ```racket
> > ( define p ( open-input-string "a abcd" ) )
> > ( regexp-match-peek ".*bc" p )
> '(#"a abc")
> > ( regexp-match-peek ".*bc" p 2 )
> '(#"abc")
> > ( regexp-match ".*bc" p 2 )
> '(#"abc")
> > ( peek-char p )
> #\d
> > ( regexp-match ".*bc" p )
> #f
> > ( peek-char p )
> #<eof>
> ```

> ```
(regexp-match-peek-positions pattern
    input
   [ start-pos
    end-pos
    progress
    input-prefix)

   →    ( or/c ( cons/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> ( listof ( or/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> #f ) ) )
> #f )

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  progress : (or/c progress-evt? #f) = #f
  input-prefix : bytes? = #""
```


# 4.6 Characters
Like regexp-match-positions on input ports, but only peeks bytes from input instead of reading them, and with a progress argument like regexp-match-peek.
> ```
(regexp-match-peek-immediate pattern
    input
   [ start-pos
    end-pos
    progress
    input-prefix)
   →    ( or/c ( cons/c bytes? ( listof ( or/c bytes? #f ) ) )
> #f )
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  progress : (or/c progress-evt? #f) = #f
  input-prefix : bytes? = #""```
Like [regexp-match-peek](#%28def._%28%28quote._~23~25kernel%29._regexp-match-peek%29%29), but it attempts to match only bytes that are available from input without blocking. The match fails if not-yet-available characters might be used to match pattern.
> ```
(regexp-match-peek-positions-immediate pattern
    input
   [ start-pos
    end-pos
    progress
    input-prefix)
   →    ( or/c ( cons/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> ( listof ( or/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> #f ) ) )
> #f )
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  progress : (or/c progress-evt? #f) = #f
  input-prefix : bytes? = #""


# 4.6 Characters
```
Like regexp-match-peek-positions, but it attempts to match only bytes that are available from input without blocking. The match fails if not-yet-available characters might be used to match pattern.

> ```
(regexp-match-peek-positions* pattern
    input
   [ start-pos
    end-pos
    input-prefix
    #:match-select match-select)

   →    ( or/c ( listof ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? ) )
> ( listof ( listof ( or/c #f ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? ) ) ) ) )

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  input-prefix : bytes? = #""
  match-select : (list? .  →  . (or/c any/c list?)) = car```

Like [regexp-match-peek-positions](#%28def._%28%28quote._~23~25kernel%29._regexp-match-peek-positions%29%29), but returns multiple matches like [regexp-match-positions*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._regexp-match-positions%2A%29%29).

> ```
(regexp-match/end pattern
    input
   [ start-pos
    end-pos
    output-port
    input-prefix
    count)

   →    ( if ( and ( or ( string? pattern ) ( regexp? pattern ) )
> ( or/c ( string? input ) ( path? input ) ) )
> ( or/c #f ( cons/c string? ( listof ( or/c string? #f ) ) ) )
> ( or/c #f ( cons/c bytes? ( listof ( or/c bytes? #f ) ) ) ) )
(or/c #f bytes?)

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? path? input-port?)
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  output-port : (or/c output-port? #f) = #f
  input-prefix : bytes? = #""
  count : exact-nonnegative-integer? = 1
```


# 4.6 Characters
Like regexp-match, but with a second result: a byte string of up to count bytes that correspond to the input (possibly including the input-prefix) leading to the end of the match; the second result is #f if no match is found.
The second result can be useful as an input-prefix for attempting a second match on input starting from the end of the first match. In that case, use regexp-max-lookbehind to determine an appropriate value for count.
> ```
(regexp-match-positions/end pattern
    input
   [ start-pos
    end-pos
    input-prefix
    count)
   →    ( listof ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? ) )
(or/c #f bytes?)
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? path? input-port?)
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  input-prefix : bytes? = #""
  count : exact-nonnegative-integer? = 1
(regexp-match-peek-positions/end   pattern
    input
   [ start-pos
    end-pos
    progress
    input-prefix
    count)
   →    ( or/c ( cons/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> ( listof ( or/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> #f ) ) )
> #f )
(or/c #f bytes?)
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  progress : (or/c progress-evt? #f) = #f
  input-prefix : bytes? = #""
  count : exact-nonnegative-integer? = 1


# 4.6 Characters
(regexp-match-peek-positions-immediate/end   pattern
    input
   [ start-pos
    end-pos
    progress
    input-prefix
    count)
   →    ( or/c ( cons/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> ( listof ( or/c ( cons/c exact-nonnegative-integer?
> exact-nonnegative-integer? )
> #f ) ) )
> #f )
(or/c #f bytes?)
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : input-port?
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  progress : (or/c progress-evt? #f) = #f
  input-prefix : bytes? = #""
  count : exact-nonnegative-integer? = 1```
Like [regexp-match-positions](#%28def._%28%28quote._~23~25kernel%29._regexp-match-positions%29%29), etc., but with a second result like [regexp-match/end](#%28def._%28%28quote._~23~25kernel%29._regexp-match%2Fend%29%29).


#### 4.8.5 Regexp Splitting
> ```
(regexp-split pattern
    input
   [ start-pos
    end-pos
    input-prefix)
   →    ( if ( and ( or ( string? pattern ) ( regexp? pattern ) )
> ( string? input ) )
> ( cons/c string? ( listof string? ) )
> ( cons/c bytes? ( listof bytes? ) ) )
  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes? input-port?)
  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  input-prefix : bytes? = #""
```
The complement of regexp-match*: the result is a list of strings (if pattern is a string or character regexp and input is a string) or byte strings (otherwise) from input that are separated by matches to pattern. Adjacent matches are separated with "" or #"". Zero-length matches are treated the same as for regexp-match*.

If input contains no matches (in the range start-pos to end-pos), the result is a list containing input’s content (from start-pos to end-pos) as a single element. If a match occurs at the beginning of input (at start-pos), the resulting list will start with an empty string or byte string, and if a match occurs at the end (at end-pos), the list will end with an empty string or byte string. The end-pos argument can be #f, in which case splitting goes to the end of input (which corresponds to an end-of-file if input is an input port).

Examples:

> ```racket
> > ( regexp-split #rx" +" "12 34" )
> '("12" "34")
> > ( regexp-split #rx"." "12 34" )
> '("" "" "" "" "" "" "")
> > ( regexp-split #rx"" "12 34" )
> '("" "1" "2" " " " " "3" "4" "")
> > ( regexp-split #rx" *" "12 34" )
> '("" "1" "2" "" "3" "4" "")
> > ( regexp-split #px"\\b" "12, 13 and 14." )
> '("" "12" ", " "13" " " "and" " " "14" ".")
> > ( regexp-split #rx" +" "" )
> '("")
> ```

#### 4.8.6 Regexp Substitution

> ```
(regexp-replace pattern
    input
    insert
   [ input-prefix)

   →    ( if ( and ( or ( string? pattern ) ( regexp? pattern ) )
> ( string? input ) )
> string?
> bytes? )

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes?)
   insert   :   ( or/c string? bytes?
> ( string? string? ... .  →  . string? )
> ( bytes? bytes? ... .  →  . bytes? ) )

  input-prefix : bytes? = #""```

Performs a match using pattern on input, and then returns a string or byte string in which the matching portion of input is replaced with insert. If pattern matches no part of input, then input is returned unmodified.

The insert argument can be either a (byte) string, or a function that returns a (byte) string. In the latter case, the function is applied on the list of values that [regexp-match](#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29) would return (i.e., the first argument is the complete match, and then one argument for each parenthesized sub-expression) to obtain a replacement (byte) string.

If pattern is a string or character regexp and input is a string, then insert must be a string or a procedure that accept strings, and the result is a string. If pattern is a byte string or byte regexp, or if input is a byte string, then insert as a string is converted to a byte string, insert as a procedure is called with a byte string, and the result is a byte string.

If insert contains &, then & is replaced with the matching portion of input before it is substituted into the match’s place. If insert contains \\‹n› for some integer ‹n›, then it is replaced with the ‹n›th matching sub-expression from input. A & and \\0 are aliases. If the ‹n›th sub-expression was not used in the match, or if ‹n› is greater than the number of sub-expressions in pattern, then \\‹n› is replaced with the empty string.

To substitute a literal & or \\, use \\& and \\\\, respectively, in insert. A \\$ in insert is equivalent to an empty sequence; this can be used to terminate a number ‹n› following \\. If a \\ in insert is followed by anything other than a digit, &, \\, or $, then the \\ by itself is treated as \\0.

Note that the \\ described in the previous paragraphs is a character or byte of insert. To write such an insert as a Racket string literal, an escaping \\ is needed before the \\. For example, the Racket constant "\\\\1" is \\1.

Examples:

> ```racket
> > ( regexp-replace #rx"mi" "mi casa" "su" )
> "su casa"
> > ( regexp-replace #rx"mi" "mi casa" string-upcase )
> "MI casa"
> > ( regexp-replace #rx"([Mm])i ([a-zA-Z]*)" "Mi Casa" "\\1y \\2" )
> "My Casa"
> > ( regexp-replace #rx"([Mm])i ([a-zA-Z]*)" "mi cerveza Mi Mi Mi" "\\1y \\2" )
> "my cerveza Mi Mi Mi"
> > ( regexp-replace #rx"x" "12x4x6" "\\\\" )
> "12\\4x6"
> > ( display ( regexp-replace #rx"x" "12x4x6" "\\\\" ) )
> 12\4x6
> ```

> ```
(regexp-replace* pattern
    input
    insert
   [ start-pos
    end-pos
    input-prefix)    →    (or/c string? bytes?)

  pattern : (or/c regexp? byte-regexp? string? bytes?)
  input : (or/c string? bytes?)
   insert   :   ( or/c string? bytes?
> ( string? string? ... .  →  . string? )
> ( bytes? bytes? ... .  →  . bytes? ) )

  start-pos : exact-nonnegative-integer? = 0
  end-pos : (or/c exact-nonnegative-integer? #f) = #f
  input-prefix : bytes? = #""
```


# 4.6 Characters
Like regexp-replace, except that every instance of pattern in input is replaced with insert, instead of just the first match. The result is input only if there are no matches, start-pos is 0, and end-pos is #f or the length of input. Only non-overlapping instances of pattern in input are replaced, so instances of pattern within inserted strings are not replaced recursively. Zero-length matches are treated the same as in regexp-match*.
The optional start-pos and end-pos arguments select a portion of input for matching; the default is the entire string or the stream up to an end-of-file.
Examples:
> ```racket
> > ( regexp-replace* #rx"(Mm)i (a-zA-Z*)" "mi cerveza Mi Mi Mi" "\\1y \\2" )
> "my cerveza My Mi Mi"
> > ( regexp-replace* #rx"(Mm)i (a-zA-Z*)" "mi cerveza Mi Mi Mi" ( lambda ( all one two ) ( string-append ( string-downcase one ) "y" ( string-upcase two ) ) ) )
> "myCERVEZA myMI Mi"
> > ( regexp-replace* #px"\\w" "hello world" string-upcase 0 5 )
> "HELLO world"
> > ( display ( regexp-replace* #rx"x" "12x4x6" "\\\\" ) )
> 12\4\6
> ```
Changed in version 8.1.0.7 of package base: Changed to return input when no replacements are performed.
> ```
(regexp-replaces input replacements) → (or/c string? bytes?)
  input : (or/c string? bytes?)
   replacements   :   ( listof
> ( list/c ( or/c regexp? byte-regexp? string? bytes? )
> ( or/c string? bytes?
> ( string? string? ... .  →  . string? )
> ( bytes? bytes? ... .  →  . bytes? ) ) ) )```


# 4.6 Characters
Performs a chain of [regexp-replace*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._regexp-replace%2A%29%29) operations, where each element in replacements specifies a replacement as a ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) pattern insert). The replacements are done in order, so later replacements can apply to previous insertions.
Examples:
> ```racket
> > ( regexp-replaces "zero-or-more?" ' ( [ #rx"-" "_" ] [ #rx"(.*)\\?$" "is_\\1" ] ) )
> "is_zero_or_more"
> > ( regexp-replaces "zero-or-more?" ' ( [ #rx"e" "o" ] [ #rx"o" "oo" ] ) )
> "zooroo-oor-mooroo?"
> ```
> ```
(regexp-replace-quote str)  →  string?
  str : string?
(regexp-replace-quote bstr)  →  bytes?
  bstr : bytes?
```
(parameter)	→```

Returns #t if v is a keyword, #f otherwise.

Examples:

> ```racket
> > ( keyword? ' #:apple )
> #t
> > ( keyword? ' define )
> #f
> > ( keyword? ' #:define )
> #t
> ```

> ```
(parameter)	→
```
(parameter)	→
(-> keyword → string ' #:apple)```
Returns a keyword whose [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29)ed form is the same as that of str, but with a leading #:.
Example:
> ```racket
> > ( string->keyword "apple" )
> '#:apple
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

procedure


# 4.6 Characters

([keyword<?](#%28def._%28%28quote._~23~25kernel%29._keyword~3c~3f%29%29) a-keyword b-keyword ...) → [boolean?](booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29)

  a-keyword : [keyword?](#%28def._%28%28quote._~23~25kernel%29._keyword~3f%29%29)

  b-keyword : [keyword?](#%28def._%28%28quote._~23~25kernel%29._keyword~3f%29%29)

Returns #t if the arguments are sorted, where the comparison for each pair of keywords is the same as using [keyword->string](#%28def._%28%28quote._~23~25kernel%29._keyword-~3estring%29%29) with [string->bytes/utf-8](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._string-~3ebytes%2Futf-8%29%29) and [bytes<?](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes~3c~3f%29%29).
Example:
> ```racket
> > ( keyword<? ' #:apple ' #:banana )> #t
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.


#### 4.9.1 Additional Keyword Functions
|                                                                                |                                                                                |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/keyword](#%28mod-path._racket%2Fkeyword%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/keyword](#%28mod-path._racket%2Fkeyword%29) library, not [racket/base](index.html) or [racket](index.html).
Added in version 7.6 of package base.
> ```
(parameter)	→
(-> and/c string? immutable?)


# 4.6 Characters
```
Like keyword  →  string, but the result is an immutable string, not necessarily freshly allocated.

Examples:

> ```racket
> > ( keyword  →  immutable-string ' #:apple )
> "apple"
> > ( immutable? ( keyword  →  immutable-string ' #:apple ) )
> #t
> ```

Added in version 7.6 of package base.

------------------------------------------------------------------------

# 4.10 Pairs and Lists

### 4.10 Pairs and Lists

> > > <img src="finger.png" width="24" height="24" alt="+" />Pairs and Lists in The Racket Guide introduces pairs and lists.

A pair combines exactly two values. The first value is accessed with the car procedure, and the second value is accessed with the cdr procedure. Pairs are not mutable (but see Mutable Pairs and Lists).

A list is recursively defined: it is either the constant null, or it is a pair whose second value is a list.

A list can be used as a single-valued sequence (see Sequences). The elements of the list serve as elements of the sequence. See also in-list.

Cyclic data structures can be created using only immutable pairs via read or make-reader-graph. If starting with a pair and using some number of cdrs returns to the starting pair, then the pair is not a list.

See Reading Pairs and Lists for information on reading pairs and lists and Printing Pairs and Lists for information on printing pairs and lists.

#### 4.10.1 Pair Constructors and Selectors

> ```
(pair? v) → boolean?
  v : any/c```

Returns #t if v is a pair, #f otherwise.

Examples:

> ```racket
> > ( pair? 1 )
> #f
> > ( pair? ( cons 1 2 ) )
> #t
> > ( pair? ( list 1 2 ) )
> #t
> > ( pair? ' ( 1 2 ) )
> #t
> > ( pair? ' ( ) )
> #f
> ```

> ```
(null? v)  →  boolean?
  v : any/c
```


# 4.6 Characters
Returns #t if v is the empty list, #f otherwise.
Examples:
> ```racket
> > ( null? 1 )
> #f
> > ( null? ' ( 1 2 ) )
> #f
> > ( null? ' ( ) )
> #t
> > ( null? ( cdr ( list 1 ) ) )
> #t
> ```
> ```
(cons a d)  →  list?
  a : any/c
  d : list?
(cons a d)  →  pair?
  a : any/c
  d : any/c
```

Returns a newly allocated pair whose first element is a and second element is d. When d is a list, the allocated pair is also a list.

Examples:

> ```racket
> > ( cons 1 2 )
> '(1 . 2)
> > ( cons 1 ' ( ) )
> '(1)
> ```

> ```
(car p)  →  any/c
  p : pair?
```
Returns the first element of the pair p.
Examples:
> ```racket
> > ( car ' ( 1 2 ) )
> 1
> > ( car ' ( 2 . 3 ) )
> 2
> ```
> ```
(cdr p)  →  any/c
  p : pair?
```

Returns the second element of the pair p.

Examples:

> ```racket
> > ( cdr ' ( 1 2 ) )
> '(2)
> > ( cdr ' ( 2 . 3 ) )
> 3
> ```

>
<colgroup><col style="width: 100%" /></colgroup>

value

[null](#%28def._%28%28quote._~23~25kernel%29._null%29%29) : [null?](#%28def._%28%28quote._~23~25kernel%29._null~3f%29%29)

The empty list.

Examples:

> ```racket
> > null
> '()
> > ' ( )
> '()
> > ( eq? ' ( ) null )
> #t
> ```

> ```
(list? v)  →  boolean?
  v : any/c
```
Returns #t if v is a list: either the empty list, or a pair whose second element is a list. This procedure effectively takes constant time due to internal caching (so that any necessary traversals of pairs can in principle count as an extra cost of allocating the pairs).


# 4.6 Characters
Examples:
> ```racket
> > ( list? ' ( 1 2 ) )
> #t
> > ( list? ( cons 1 ( cons 2 ' ( ) ) ) )
> #t
> > ( list? ( cons 1 2 ) )
> #f
> ```
> ```
(list v ...) → list?
  v : any/c```
Returns a newly allocated list containing the vs as its elements.
Examples:
> ```racket
> > ( list 1 2 3 4 )
> '(1 2 3 4)
> > ( list ( list 1 2 ) ( list 3 4 ) )
> '((1 2) (3 4))
> ```
> ```
(list* v ... tail) → list?
  v : any/c
  tail : list?
(list* v ... tail)  →  any/c
  v : any/c
  tail : any/c
```
Like list, but the last argument is used as the tail of the result, instead of the final element. The result is a list only if the last argument is a list.

Examples:

> ```racket
> > ( list* 1 2 3 )
> '(1 2 . 3)
> > ( list* 1 2 ( list 3 4 ) )
> '(1 2 3 4)
> ```

> ```
(build-list n proc)   →   list?
  n : exact-nonnegative-integer?
  proc : (exact-nonnegative-integer? .  →  . any/c)```

Creates a list of n elements by applying proc to the integers from 0 to ([sub1](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._sub1%29%29) n) in order. If lst is the resulting list, then ([list-ref](#%28def._%28%28quote._~23~25kernel%29._list-ref%29%29) lst i) is the value produced by (proc i).

Examples:

> ```racket
> > ( build-list 10 values )
> '(0 1 2 3 4 5 6 7 8 9)
> > ( build-list 5 ( lambda ( x ) ( * x x ) ) )
> '(0 1 4 9 16)
> ```

#### 4.10.2 List Operations

> ```
(length lst)  →  exact-nonnegative-integer?
  lst : list?
```
Returns the number of elements in lst. This function takes time proportional to that length.
Examples:


# 4.6 Characters
> ```racket
> > ( length ( list 1 2 3 4 ) )
> 4
> > ( length ' ( ) )
> 0
> ```
> ```
(list-ref lst pos)  →  any/c
  lst : list?
  pos : exact-nonnegative-integer?
(list-ref lst pos)  →  any/c
  lst : pair?
  pos : exact-nonnegative-integer?
```

Returns the element of lst at position pos, where the list’s first element is position 0. If the list has pos or fewer elements, then the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.

The lst argument need not actually be a list; lst must merely start with a chain of at least ([add1](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._add1%29%29) pos) pairs.

This function takes time proportional to pos.

Examples:

> ```racket
> > ( list-ref ( list ' a ' b ' c ) 0 )
> 'a
> > ( list-ref ( list ' a ' b ' c ) 1 )
> 'b
> > ( list-ref ( list ' a ' b ' c ) 2 )
> 'c
> > ( list-ref ( cons 1 2 ) 0 )
> 1
> > ( list-ref ( cons 1 2 ) 1 )
> list-ref: index reaches a non-pair
> index: 1
> in: '(1 . 2)
> ```

> ```
(list-tail lst pos)  →  list?
  lst : list?
  pos : exact-nonnegative-integer?
(list-tail lst pos)  →  any/c
  lst : any/c
  pos : exact-nonnegative-integer?
```
Returns the list after the first pos elements of lst. If the list has fewer than pos elements, then the exn:fail:contract exception is raised.
The lst argument need not actually be a list; lst must merely start with a chain of at least pos pairs.
This function takes time proportional to pos.
Examples:


# 4.6 Characters
> ```racket
> > ( list-tail ( list 1 2 3 4 5 ) 2 )
> '(3 4 5)
> > ( list-tail ( cons 1 2 ) 1 )
> 2
> > ( list-tail ( cons 1 2 ) 2 )
> list-tail: index reaches a non-pair
> index: 2
> in: '(1 . 2)
> > ( list-tail ' not-a-pair 0 )
> 'not-a-pair
> ```
> ```
(append lst ...) → list?
  lst : list?
(append lst ... v)   →   any/c
  lst : list?
  v : any/c```
When given all list arguments, the result is a list that contains all of the elements of the given lists in order. The last argument is used directly in the tail of the result.
The last argument need not be a list, in which case the result is an “improper list.”
This function takes time proportional to the length of all arguments (added together) except the last argument.
Examples:
> ```racket
> > ( append ( list 1 2 ) ( list 3 4 ) )
> '(1 2 3 4)
> > ( append ( list 1 2 ) ( list 3 4 ) ( list 5 6 ) ( list 7 8 ) )
> '(1 2 3 4 5 6 7 8)
> ```
> ```
(reverse lst)  →  list?
  lst : list?


# 4.6 Characters
```
Returns a list that has the same elements as lst, but in reverse order.

This function takes time proportional to the length of lst.

Example:

> ```racket
> > ( reverse ( list 1 2 3 4 ) )
> '(4 3 2 1)
> ```

#### 4.10.3 List Iteration

> ```
(map proc lst ...+) → list?
  proc : procedure?
  lst : list?```

Applies proc to the elements of the lsts from the first elements to the last. The proc argument must accept the same number of arguments as the number of supplied lsts, and all lsts must have the same number of elements. The result is a list containing each result of proc in order.

Examples:

> ```racket
> > ( map ( lambda ( number ) ( + 1 number ) ) ' ( 1 2 3 4 ) )
> '(2 3 4 5)
> > ( map ( lambda ( number1 number2 ) ( + number1 number2 ) ) ' ( 1 2 3 4 ) ' ( 10 100 1000 10000 ) )
> '(11 102 1003 10004)
> ```

> ```
(andmap proc lst ...+) → any
  proc : procedure?
  lst : list?
```
Similar to map in the sense that proc is applied to each element of lst, but
> > > The andmap function is actually closer to foldl than map, since andmap doesn’t produce a list. Still, (andmap f (list x y z)) is equivalent to (and (f x) (f y) (f z)) in the same way that (map f (list x y z)) is equivalent to (list (f x) (f y) (f z)).
-  the result is #f if any application of proc produces #f, in which case proc is not applied to later elements of the lsts; and
-  the result is that of proc applied to the last elements of the lsts; more specifically, the application of proc to the last elements in the lsts is in tail position with respect to the andmap call.


# 4.6 Characters
If the lsts are empty, then #t is returned.
Examples:
> ```racket
> > ( andmap positive? ' ( 1 2 3 ) )
> #t
> > ( andmap positive? ' ( 1 2 a ) )
> positive?: contract violation
> expected: real?
> given: 'a
> > ( andmap positive? ' ( 1 -2 a ) )
> #f
> > ( andmap + ' ( 1 2 3 ) ' ( 4 5 6 ) )
> 9
> ```
> ```
(ormap proc lst ...+) → any
  proc : procedure?
  lst : list?```
Similar to [map](#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29) in the sense that proc is applied to each element of lst, but
> > > To continue the [andmap](#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._andmap%29%29) note above, ([ormap](#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._ormap%29%29) f ([list](#%28def._%28%28quote._~23~25kernel%29._list%29%29) x y z)) is equivalent to ([or](if.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._or%29%29) (f x) (f y) (f z)).
-   the result is #f if every application of proc produces #f; and
-   the result is that of the first application of proc producing a value other than #f, in which case proc is not applied to later elements of the lsts; the application of proc to the last elements of the lsts is in tail position with respect to the [ormap](#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._ormap%29%29) call.
If the lsts are empty, then #f is returned.
Examples:
> ```racket
> > ( ormap eq? ' ( a b c ) ' ( a b c ) )
> #t
> > ( ormap positive? ' ( 1 2 a ) )
> #t
> > ( ormap + ' ( 1 2 3 ) ' ( 4 5 6 ) )
> 5
> ```
> ```
(parameter)	→


# 4.6 Characters
```
Similar to map, but proc is called only for its effect, and its result (which can be any number of values) is ignored.

Example:

> ```racket
> > ( for-each ( lambda ( arg ) ( printf "Got ~a\n" arg ) 23 ) ' ( 1 2 3 4 ) )
> Got 1 Got 2 Got 3 Got 4
> ```

> ```
(foldl proc init lst ...+) → any/c
  proc : procedure?
  init : any/c
  lst : list?```

Like [map](#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29), [foldl](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29) applies a procedure to the elements of one or more lists. Whereas [map](#%28def._%28%28lib._racket%2Fprivate%2Fmap..rkt%29._map%29%29) combines the return values into a list, [foldl](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29) combines the return values in an arbitrary way that is determined by proc.

If [foldl](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29) is called with n lists, then proc must take n+1 arguments. The extra argument is the combined return values so far. The proc is initially invoked with the first item of each list, and the final argument is init. In subsequent invocations of proc, the last argument is the return value from the previous invocation of proc. The input lsts are traversed from left to right, and the result of the whole [foldl](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29) application is the result of the last application of proc. If the lsts are empty, the result is init.

Unlike [foldr](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldr%29%29), [foldl](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29) processes the lsts in constant space (plus the space for each call to proc).

Examples:

> ```racket
> > ( foldl cons ' ( ) ' ( 1 2 3 4 ) )
> '(4 3 2 1)
> > ( foldl + 0 ' ( 1 2 3 4 ) )
> 10
> > ( foldl ( lambda ( a b result ) ( * result ( - a b ) ) ) 1 ' ( 1 2 3 ) ' ( 4 5 6 ) )
> -27
> ```

> ```
(foldr proc init lst ...+) → any/c
  proc : procedure?
  init : any/c
  lst : list?
```


# 4.6 Characters
Like foldl, but the lists are traversed from right to left. Unlike foldl, foldr processes the lsts in space proportional to the length of lsts (plus the space for each call to proc).
Examples:
> ```racket
> > ( foldr cons ' ( ) ' ( 1 2 3 4 ) )
> '(1 2 3 4)
> > ( foldr ( lambda ( v l ) ( cons ( add1 v ) l ) ) ' ( ) ' ( 1 2 3 4 ) )
> '(2 3 4 5)
> ```


#### 4.10.4 More List Iteration
|  |  |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------|
|  (require racket/list/iteration) |  |
|    |  package: sequence-tools-lib |
The bindings documented in this section are provided by the racket/list/iteration library, not racket/base or racket.
The bindings in this section are provided by the sequence-tools-lib package, which acts as an extension to the base sequence libraries.
> ```
(running-foldl proc init lst ...+) → list?
  proc : procedure?
  init : any/c
  lst : list?```
Like [foldl](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._foldl%29%29), but produces a list containing all the results of applying proc as well as the initial accumulator.
Examples:
> ```racket
> > ( running-foldl + 0 ' ( 1 2 3 ) )
> '(0 1 3 6)
> > ( running-foldl + 0 ' ( ) )
> '(0)
> > ( running-foldl ( lambda ( a b acc ) ( * acc ( + a b ) ) ) 1 ' ( 1 2 ) ' ( 3 4 ) )
> '(1 4 24)
> ```
> ```
(running-foldr proc init lst ...+) → list?
  proc : procedure?
  init : any/c
  lst : list?


# 4.6 Characters
```
Like running-foldl, but produces the intermediate results from the right like foldr.

Examples:

> ```racket
> > ( running-foldr + 0 ' ( 1 2 3 ) )
> '(6 5 3 0)
> > ( running-foldr + 0 ' ( ) )
> '(0)
> > ( running-foldr ( lambda ( a b acc ) ( * acc ( + a b ) ) ) 1 ' ( 1 2 ) ' ( 3 4 ) )
> '(24 6 1)
> ```

#### 4.10.5 List Filtering

> ```
(filter pred lst)   →   list?
  pred : procedure?
  lst : list?```

Returns a list with the elements of lst for which pred produces a true value. The pred procedure is applied to each element from first to last.

Example:

> ```racket
> > ( filter positive? ' ( 1 -2 3 4 -5 ) )
> '(1 3 4)
> ```

> ```
(remove v lst [proc) → list?
  v : any/c
  lst : list?
  proc : procedure? = equal?
```
Returns a list that is like lst, omitting the first element of lst that is equal to v using the comparison procedure proc (which must accept two arguments), with v as the first argument and an element in lst as the second argument. If no element in lst is equal to v (according to proc), lst is returned unchanged.
Examples:
> ```racket
> > ( remove 2 ( list 1 2 3 2 4 ) )
> '(1 3 2 4)
> > ( remove ' ( 2 ) ( list ' ( 1 ) ' ( 2 ) ' ( 3 ) ) )
> '((1) (3))
> > ( remove "2" ( list "1" "2" "3" ) )
> '("1" "3")
> > ( remove #\c ( list #\a #\b #\c ) )
> '(#\a #\b)
> > ( remove "B" ( list "a" "A" "b" "B" ) string-ci=? )
> '("a" "A" "B")
> > ( remove 5 ( list 1 2 3 2 4 ) )
> '(1 2 3 2 4)
> ```
Changed in version 8.2.0.2 of package base: Guaranteed that the output is eq? to lst if no removal occurs.
> ```


# 4.6 Characters
(remq v lst) → list?
  v : any/c
  lst : list?```
Returns ([remove](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._remove%29%29) v lst [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29)).
Examples:
> ```racket
> > ( remq 2 ( list 1 2 3 4 5 ) )
> '(1 3 4 5)
> > ( remq ' ( 2 ) ( list ' ( 1 ) ' ( 2 ) ' ( 3 ) ) )
> '((1) (2) (3))
> > ( remq "2" ( list "1" "2" "3" ) )
> '("1" "3")
> > ( remq #\c ( list #\a #\b #\c ) )
> '(#\a #\b)
> ```
> ```
(remv v lst)  →  list?
  v : any/c
  lst : list?
```
Returns (remove v lst eqv?).

Examples:

> ```racket
> > ( remv 2 ( list 1 2 3 4 5 ) )
> '(1 3 4 5)
> > ( remv ' ( 2 ) ( list ' ( 1 ) ' ( 2 ) ' ( 3 ) ) )
> '((1) (2) (3))
> > ( remv "2" ( list "1" "2" "3" ) )
> '("1" "3")
> > ( remv #\c ( list #\a #\b #\c ) )
> '(#\a #\b)
> ```

> ```
(remw v lst)   →   list?
  v : any/c
  lst : list?```

Returns ([remove](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._remove%29%29) v lst [equal-always?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal-always~3f%29%29)).

Examples:

> ```racket
> > ( remw 2 ( list 1 2 3 4 5 ) )
> '(1 3 4 5)
> > ( remw ' ( 2 ) ( list ' ( 1 ) ' ( 2 ) ' ( 3 ) ) )
> '((1) (3))
> > ( remw "2" ( list "1" "2" "3" ) )
> '("1" "3")
> > ( remw #\c ( list #\a #\b #\c ) )
> '(#\a #\b)
> > ( define b1 ( box 5 ) )
> > ( define b2 ( box 5 ) )
> > ( remw b2 ( list 0 b1 1 b2 2 ) )
> '(0 #&5 1 2)
> ```

Added in version 8.5.0.3 of package base.

> ```
(remove* v-lst lst [proc) → list?
  v-lst : list?
  lst : list?
  proc : procedure? = equal?
```


# 4.6 Characters
Like remove, but removes from lst every instance of every element of v-lst.
Example:
> ```racket
> > ( remove* ( list 1 2 ) ( list 1 2 3 2 4 5 2 ) )
> '(3 4 5)
> ```
Changed in version 8.2.0.2 of package base: Guaranteed that the output is eq? to lst if no removal occurs.
> ```
(remq* v-lst lst)   →   list?
  v-lst : list?
  lst : list?```
Returns ([remove*](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._remove%2A%29%29) v-lst lst [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29)).
Example:
> ```racket
> > ( remq* ( list 1 2 ) ( list 1 2 3 2 4 5 2 ) )
> '(3 4 5)
> ```
> ```
(remv* v-lst lst)  →  list?
  v-lst : list?
  lst : list?
```
Returns (remove* v-lst lst eqv?).

Example:

> ```racket
> > ( remv* ( list 1 2 ) ( list 1 2 3 2 4 5 2 ) )
> '(3 4 5)
> ```

> ```
(remw* v-lst lst)   →   list?
  v-lst : list?
  lst : list?```

Returns ([remove*](#%28def._%28%28lib._racket%2Fprivate%2Flist..rkt%29._remove%2A%29%29) v-lst lst [equal-always?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal-always~3f%29%29)).

Examples:

> ```racket
> > ( remw* ( list 1 2 ) ( list 1 2 3 2 4 5 2 ) )
> '(3 4 5)
> > ( define b1 ( box 5 ) )
> > ( define b2 ( box 5 ) )
> > ( remw* ( list b2 ) ( list 0 b1 1 b2 2 b2 3 ) )
> '(0 #&5 1 2 3)
> ```

Added in version 8.5.0.3 of package base.

> ```
(sort lst
    less-than?
   [ #:key extract-key
    #:cache-keys? cache-keys?)    →    list?

  lst : list?
  less-than? : (any/c any/c .  →  . any/c)
  extract-key : (or/c #f (any/c .  →  . any/c)) = #f
  cache-keys? : boolean? = #f
```


# 4.6 Characters
Returns a list sorted according to the less-than? procedure, which takes two elements of lst and returns a true value if the first is less (i.e., should be sorted earlier) than the second.
The sort is stable; if two elements of lst are “equal” (i.e., less-than? does not return a true value when given the pair in either order), then the elements preserve their relative order from lst in the output list. To preserve this guarantee, use sort with a strict comparison functions (e.g., < or string<?; not <= or string<=?).
> > > Because of the peculiar fact that the IEEE-754 number system specifies that +nan.0 is neither greater nor less than nor equal to any other number, sorting lists containing this value may produce a surprising result.
The #:key argument extract-key is used to extract a key value for comparison from each list element, where #f is replaced by (lambda (x) x) That is, the full comparison procedure is essentially
> ```racket
> ( lambda ( x y )
> ( less-than? ( extract-key x ) ( extract-key y ) ) )
> ```


# 4.6 Characters
By default, extract-key is applied to two list elements for every comparison, but if cache-keys? is true, then the extract-key function is used exactly once for each list item. Supply a true value for cache-keys? when extract-key is an expensive operation; for example, if file-or-directory-modify-seconds is used to extract a timestamp for every file in a list, then cache-keys? should be #t to minimize file-system calls, but if extract-key is car, then cache-keys? should be #f. As another example, providing extract-key as (lambda (x) (random)) and #t for cache-keys? effectively shuffles the list.
Examples:
> ```racket
> > ( sort ' ( 1 3 4 2 ) < )> '(1 2 3 4)
> > ( sort ' ( "aardvark" "dingo" "cow" "bear" ) string<? )> '("aardvark" "bear" "cow" "dingo")
> > ( sort ' ( ( "aardvark" ) ( "dingo" ) ( "cow" ) ( "bear" ) ) #:key car string<? )> '(("aardvark") ("bear") ("cow") ("dingo"))
> ```


#### 4.10.6 List Searching
> ```
(member v lst [is-equal?) → (or/c #f list?)
  v : any/c
  lst : list?
  is-equal? : (any/c any/c .  →  . any/c) = equal?
(member v lst [is-equal?)   →   any/c
  v : any/c
  lst : any/c
  is-equal? : (any/c any/c .  →  . any/c) = equal?```
Locates the first element of lst that is equal to v according to is-equal?. If such an element exists, the tail of lst starting with that element is returned. Otherwise, the result is #f.
The lst argument need not actually be a list; lst must merely start with a chain of pairs until a matching element is found. If no matching element is found, then lst must be a list (and not a cyclic list). The result can be a non-list in the case that an element is found and the returned tail of lst is a non-list.
Examples:
> ```racket
> > ( member 2 ( list 1 2 3 4 ) )
> '(2 3 4)
> > ( member 9 ( list 1 2 3 4 ) )
> #f
> > ( member #' x ( list #' x #' y ) free-identifier=? )
> '(#<syntax:eval:579:0 x> #<syntax:eval:579:0 y>)
> > ( member #' a ( list #' x #' y ) free-identifier=? )
> #f
> > ( member ' b ' ( a b . etc ) )
> '(b . etc)
> > ( member ' c ' ( a b . etc ) )
> member: not a proper list
> in: '(a b . etc)
> ```
> ```
(memw v lst)  →  (or/c #f list?)
  v : any/c
  lst : list?
(memw v lst)  →  any/c
  v : any/c
  lst : any/c