Node:Rx Regexps, Next:Expect, Previous:Formatted Output, Up:Top
[FIXME: this is taken from Gary and Mark's quick summaries and should be reviewed and expanded. Rx is pretty stable, so could already be done!]
The guile-lang-allover
package provides an interface to Tom
Lord's Rx library (currently only to POSIX regular expressions). Use of
the library requires a two step process: compile a regular expression
into an efficient structure, then use the structure in any number of
string comparisons.
For example, given the regular expression abc.
(which matches any
string containing abc
followed by any single character):
guile> (define r (regcomp "abc.")) guile> r #<rgx abc.> guile> (regexec r "abc") #f guile> (regexec r "abcd") #((0 . 4)) guile>
The definitions of regcomp
and regexec
are as follows:
regcomp pattern [flags] | Scheme Procedure |
Compile the regular expression pattern using POSIX rules. Flags is
optional and should be specified using symbolic names:
The |
regexec regex string [match-pick] [flags] | Scheme Procedure |
Match string against the compiled POSIX regular expression
regex.
match-pick and flags are optional. Possible flags (which can be
combined using the logior procedure) are:
If no match is possible, regexec returns #f. Otherwise match-pick determines the return value:
vector: the supplied vector is returned, with the first element replaced by a pair containing the indices of the matched portion of string and further elements replaced by pairs containing the indices of matched substrings (if any). list: a list will be returned, with each member of the list specified by a code in the corresponding position of the supplied list: a number: the numbered matching substring (0 for the entire match).
e.g., |
Here are some other procedures that might be used when using regular expressions:
compiled-regexp? obj | Scheme Procedure |
Test whether obj is a compiled regular expression. |
regexp->dfa regex [flags] | Scheme Procedure |
dfa-fork dfa | Scheme Procedure |
reset-dfa! dfa | Scheme Procedure |
dfa-final-tag dfa | Scheme Procedure |
dfa-continuable? dfa | Scheme Procedure |
advance-dfa! dfa string | Scheme Procedure |