(chibi regexp)

A regular expression engine implementing SRFI 115 using a non-backtracking Thompson NFA algorithm.

(rx sre ...)

(regexp-match-count md)

(regexp-match-submatch/list md n)

Returns the matching result for the given named or indexed submatch n, possibly as a list for a submatch-list, or #f if not matched.

(regexp-match-submatch md n)

Returns the matching substring for the given named or indexed submatch n, or #f if not matched.

(regexp-match-submatch-start md n)

Returns the start index for the given named or indexed submatch n, or #f if not matched.

(regexp-match-submatch-end md n)

Returns the end index for the given named or indexed submatch n, or #f if not matched.

(regexp-match->list md)

Convert an regexp-match result to a list of submatches, beginning with the full match, using #f for unmatched submatches.

(regexp-match->sexp md)

Convert an regexp-match result to a forest of submatches, beginning with the full match, using #f for unmatched submatches.

(regexp-matches rx str . o)

Match the given regexp or SRE against the entire string and return the match data on success. Returns #f on failure.

(regexp-matches? rx str . o)

Match the given regexp or SRE against the entire string and return the #t on success. Returns #f on failure.

(regexp-search rx str . o)

Search for the given regexp or SRE within string and return the match data on success. Returns #f on failure.

(valid-sre? x)

(char-set->sre cset)

(regexp sre . o)

Compile an sre into a regexp.

(regexp-fold rx kons knil str [finish])

The fundamental regexp matching iterator. Repeatedly searches str for the regexp re so long as a match can be found. On each successful match, applies (kons i regexp-match str acc) where i is the index since the last match (beginning with start),regexp-match is the resulting match, and acc is the result of the previous kons application, beginning with knil. When no more matches can be found, calls finish with the same arguments, except that regexp-match is #f. By default finish just returns acc.

(regexp-extract rx str . o)

Extracts all non-empty substrings of str which match re between start and end as a list of strings.

(regexp-split rx str [start end])

Splits str into a list of strings separated by matches of re.

(regexp-partition rx str [start end])

Partitions str into a list of non-empty strings matching re, interspersed with the unmatched portions of the string. The first and every odd element is an unmatched substring, which will be the empty string if re matches at the beginning of the string or end of the previous match. The second and every even element will be a substring matching re. If the final match ends at the end of the string, no trailing empty string will be included. Thus, in the degenerate case where str is the empty string, the result is ("").

(regexp-replace rx str subst [count])

Returns a new string replacing the countth match of re in str the subst, where the zero-indexed count defaults to zero (i.e. the first match). If there are not count matches, returns the selected substring unmodified. subst can be a string, an integer or symbol indicating the contents of a numbered or named submatch of re,'pre for the substring to the left of the match, or 'post for the substring to the right of the match. The optional parameters start and end restrict both the matching and the substitution, to the given indices, such that the result is equivalent to omitting these parameters and replacing on (substring str start end). As a convenience, a value of #f for end is equivalent to (string-length str).

(regexp-replace-all rx str subst . o)

Equivalent to regexp-replace, but replaces all occurrences of re in str.