Scheme 48 Manual | Contents | In Chapter: Access to POSIX
Previous: Regular expressions | Next: Regular expressions

## Regular expressions

The procedures in this section provide access to POSIX regular expression matching. The regular expression syntax and semantics are far too complex to be described here. Because the C interface uses zero bytes for marking the ends of strings, patterns and strings that contain zero bytes will not work correctly.

These procedures are in structures `posix-regexps` and `posix`.

An abstract data type for creating POSIX regular expressions is described in section *.

- `(make-regexp string . regexp-options) -> regexp`

- `(regexp-option `option-name`) -> regexp-option` | syntax

`Make-regexp` makes a new regular expression, using `string` as the pattern. The possible option names are:

> `extended` | use the extended patterns
> `ignore-case` | ignore case when matching
> `submatches` | report submatches
> `newline` | treat newlines specially

The regular expression is not compiled until it matched against a string, so any errors in the pattern string will not be reported until that point.

- `(regexp? x) -> boolean`

This is a predicate for regular expressions.

- `(regexp-match regexp string start submatches? starts-line? ends-line?)`
  `-> boolean or list of matches`
- `(match? x) -> boolean`
- `(match-start match) -> integer`
- `(match-end match) -> integer`

`Regexp-match` matches the regular expression against the characters in `string`, starting at position `start`. If the string does not match the regular expression, `regexp-match` returns `#f`. If the string does match, then a list of match records is returned if `submatches?` is true, or `#t` is returned if it is not. Each match record contains the index of the character at the beginning of the match and one more than the index of the character at the end. The first match record gives the location of the substring that matched `regexp`. If the pattern in `regexp` contained submatches, then the results of these are returned in order, with a match records reporting submatches that succeeded and `#f` in place of those that did not.

`Starts-line?` should be true if `string` starts at the beginning of a line and `ends-line?` should be true if it ends one.

Previous: Regular expressions | Next: Regular expressions