chickadee » posix-regex


A thin wrapper around POSIX regular expression matching.


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. Similar to the POSIX interface, a procedure for performing substitutions based on a matched regex is not included out-of-the-box, but can easily be implemented on top.




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


make-regex pattern #!optional ignorecase extended multilineprocedure

Returns a pre-compiled regular expression object for the given pattern. The optional arguments ignorecase and extended specify whether the case should be ignored during matching and if ERE (instead of BRE) syntax should be used. The remaining multiline optional argument will cause the string to be treated as multiple lines (affects handling of ^ and $). If an error occurs during regex compilation, an exception is raised.


regex? objprocedure

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


regex-exec regex bytevector #!optional notbol noteolprocedure

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. The first pair in the vector corresponds to the matched substring for the entire regular expression.

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? regex string #!optional notbol noteolprocedure

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.

Version History

Initial release.


This module is licensed under GPL-3.0-only.

Contents »