You are looking at historical revision 41210 of this page. It may differ significantly from its current revision.

posix-regex

A thin wrapper around POSIX regular expression matching.

Introduction

This module provides support for regular expressions. Contrary to irregex, it strictly targets Basic Regular Expressions (BREs) as well as Extended Regular Expressions (EREs) as defined in POSIX. For this purpose, it provides a small wrapper around the regcomp(3) and regexec(3) functions provided by your libc.

Repository

https://github.com/nmeum/posix-regex

Requirements

Usage

(import posix-regex)

API

The following subsections provide a brief description of the provided procedures.

make-regex

[procedure] (make-regex pattern #!optional ignorecase extended newline)

Returns a pre-compiled regular expression object for the given pattern. The optional arguments ignorecase, extended, and newline specify whether the case should be ignored during matching, if extended regular expression syntax should be supported, and if #\newline in a pattern should not be treated as an ordinary character. All optional arguments default to #f.

regex?

[procedure] (regex? obj)

Returns #t if obj is a pre-compiled regular expression, or #f otherwise.

regex-exec

[procedure] (regex-exec regex bytevector #!optional notbol noteol)

Execute the given regex on the given bytevector. Returns #f if the match failed or a vector of matching subexpressions. In the vector, each element is either #f (for non-participating optional submatches) or a pair of bytevector offsets. The first element in the pair specifies the beginning of the submatch in the bytevector, the second element specifies the end of the submatch. If the submatch does not participate in a succesfull match, then both the start and end index are set to -1.

The optional notbol and noteol procedure arguments control whether the first/last character of the input should be considered the start/end of the line.

regex-match?

[procedure] (regex-match? regex string #!optional notbol noteol)

Check whether the given regex is matched by the given string. If so #t is returned, otherwise #f is returned. This procedure is essentially a variant of regex-exec which supports strings instead of bytevectors directly and thus doesn't support submatches. Refer to regex-exec for documentation on the optional notbol and noteol procedure parameters.

License

This module is licensed under GPL-3.0-only.