Scheme 48 Manual | Contents | In Chapter: Access to POSIX
Previous: I/O | Next: C to Scheme correspondence

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 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.

This is a predicate for regular expressions. Regexp-match matches the regular expression against the characters in string. 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: I/O | Next: C to Scheme correspondence