1. posix-regex
    1. Introduction
    2. Repository
    3. Requirements
    4. API
      1. make-regex
      2. regex?
      3. regex-exec
      4. regex-match?
    5. Version History
    6. License

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

Repository

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

Requirements

API

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

make-regex

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

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?

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

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

Version History

0.1.0
Initial release.

License

This module is licensed under GPL-3.0-only.