Regular Expressions Functions

function SRFI-115/regexp sre [flags]

Compiles a regexp if given an object whose structure matches the SRE syntax.

Returns sre unmodified if it is already a regexp.

Param sre:

SRE

Param sre:

list

Param flags:

flags

Param flags:

list

Return:

regexp

Rtype:

struct-instance

Raises ^rt-parameter-value-error:

function SRFI-115/regexp? o

Is o a regexp?

Param o:

value to test

Type o:

any

Return:

boolean

function SRFI-115/valid-sre? x

Is x a valid SRE?

Param x:

value to test

Type x:

any

Return:

boolean

function SRFI-115/rx sre ...

define-template: (rx & args) (x e)

This is a syntax transformer compiling sre … into a sequence regular expression

(regexp #T{ (: sre ...) })

function SRFI-115/regexp->sre re

Returns an SRE corresponding to the given regexp re.

Param re:

regexp

Type re:

struct-instance

Return:

SRE

Rtype:

list

function SRFI-115/char-set->sre cset

Returns an SRE corresponding to the given SRFI 14 character set cset.

Param cset:

SRFI-14 character set

Type cset:

struct-instance

Return:

SRE

Type cset:

list

function SRFI-115/regexp-matches re str [start [end]]

Returns an regexp-match object if re successfully matches the entire string str from start (inclusive) to end (exclusive), or #f if the match fails. The regexp-match object will contain information needed to extract any submatches.

Param re:

SRE or regexp

Type re:

list or struct-instance

Param str:

string to match

Type str:

string

Param start:

starting index, defaults to 0

Type start:

integer, optional

Param end:

ending index, defaults to string length

Type end:

integer, optional

Return:

regexp-match object

Rtype:

struct-instance

function SRFI-115/regexp-matches? rx str [o]

Returns #t if re matches str as in regexp-matches, or #f otherwise.

Param re:

SRE or regexp

Type re:

list or struct-instance

Param str:

string to match

Type str:

string

Return:

boolean

function SRFI-115/regexp-replace re str subst [start [end [count]]]

Returns a new string replacing the count th 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).

Param re:

SRE or regexp

Type re:

list or struct-instance

Param str:

string to match

Type str:

string

Param subst:

replacement

Type subst:

see above

Param start:

starting index, defaults to 0

Type start:

integer, optional

Param end:

ending index, defaults to string length

Type end:

integer or #f, optional

Param count:

replacement index count, defaults to zero

Type count:

integer, optional

Return:

(possibly) modified string

Rtype:

string

function SRFI-115/regexp-replace-all re str subst [start [end]]

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

Param re:

SRE or regexp

Type re:

list or struct-instance

Param str:

string to match

Type str:

string

Param subst:

replacement

Type subst:

see above

Param start:

starting index, defaults to 0

Type start:

integer, optional

Param end:

ending index, defaults to string length

Type end:

integer or #f, optional

Return:

(possibly) modified string

Rtype:

string

function SRFI-115/regexp-fold re kons knil str [finish [start [end]]]

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.

Param re:

SRE or regexp

Type re:

list or struct-instance

Param kons:

accumulation function

Type kons:

function

Param knil:

accumlated result

Type knil:

any

Param str:

string to match

Type str:

string

Param finish:

result function, defaults to a function returning acc

Type finish:

function, optional

Param start:

starting index, defaults to 0

Type start:

integer, optional

Param end:

ending index, defaults to string length

Type end:

integer or #f, optional

Return:

according to finish

Rtype:

any

function SRFI-115/regexp-extract re str [start [end]]

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

Param re:

SRE or regexp

Type re:

list or struct-instance

Param str:

string to match

Type str:

string

Param start:

starting index, defaults to 0

Type start:

integer, optional

Param end:

ending index, defaults to string length

Type end:

integer, optional

Return:

list of matching strings

Rtype:

list

function SRFI-115/regexp-split re str [start [end]]

Splits str into a list of (possibly empty) strings separated by non-empty matches of re.

Param re:

SRE or regexp

Type re:

list or struct-instance

Param str:

string to match

Type str:

string

Param start:

starting index, defaults to 0

Type start:

integer, optional

Param end:

ending index, defaults to string length

Type end:

integer, optional

Return:

list of matching strings

Rtype:

list

function SRFI-115/regexp-partition re 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 ("") .

Note that regexp-partition is equivalent to interleaving the results of regexp-split and regexp-extract, starting with the former.

Param re:

SRE or regexp

Type re:

list or struct-instance

Param str:

string to match

Type str:

string

Param start:

starting index, defaults to 0

Type start:

integer, optional

Param end:

ending index, defaults to string length

Type end:

integer, optional

Return:

list of matching strings

Rtype:

list

function SRFI-115/regexp-match? o

Is o a successful match from regexp-matches or regexp-search?

Param o:

value to test

Type o:

any

Return:

boolean

function SRFI-115/regexp-match-count regexp-match

Returns the number of submatches of regexp-match, regardless of whether they matched or not. Does not include the implicit zero full match in the count.

Param regexp-match:

regexp-match

Type regexp-match:

struct-instance

Return:

number of submatches

Rtype:

integer

function SRFI-115/regexp-match-submatch regexp-match field

Returns the substring matched in regexp-match corresponding to field, either an integer or a symbol for a named submatch. Index 0 refers to the entire match, index 1 to the first lexicographic submatch, and so on. If there are multiple submatches with the same name, the first which matched is returned. If passed an integer outside the range of matches, or a symbol which does not correspond to a named submatch of the pattern, it is an error. If the corresponding submatch did not match, returns false.

The result of extracting a submatch after the original matched string has been mutated is unspecified.

Param regexp-match:

regexp-match

Type regexp-match:

struct-instance

Param field:

field identifier

Type field:

integer or symbol

Return:

submatch string or #f

Rtype:

string or #f

function SRFI-115/regexp-match-submatch-start regexp-match field

Returns the start index for regexp-match corresponding to field as per regexp-match-submatch.

Param regexp-match:

regexp-match

Type regexp-match:

struct-instance

Param field:

field identifier

Type field:

integer or symbol

Return:

submatch starting index

Rtype:

integer

function SRFI-115/regexp-match-submatch-end regexp-match field

Returns the end index for regexp-match corresponding to field as per regexp-match-submatch.

Param regexp-match:

regexp-match

Type regexp-match:

struct-instance

Param field:

field identifier

Type field:

integer or symbol

Return:

submatch ending index

Rtype:

integer

function SRFI-115/regexp-match->list regexp-match

Returns a list of all submatches in regexp-match as string or false, beginning with the entire match 0.

Param regexp-match:

regexp-match

Type regexp-match:

struct-instance

Return:

list of submatches

Rtype:

list

function SRFI-115/regexp-match->sexp regexp-match

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

Param regexp-match:

regexp-match

Type regexp-match:

struct-instance

Return:

sexp

Rtype:

list

Last built at 2024-10-13T06:10:42Z+0000 from 62cca4c (dev) for Idio 0.3.b.6