By default, Guile supports POSIX extended regular expressions. That means that the characters `(', `)', `+' and `?' are special, and must be escaped if you wish to match the literal characters.
This regular expression interface was modeled after that implemented by SCSH, the Scheme Shell. It is intended to be upwardly compatible with SCSH regular expressions.
string-match
returns a match structure which
describes what, if anything, was matched by the regular
expression. See section Match Structures. If str does not match
pattern at all, string-match
returns #f
.
Each time string-match
is called, it must compile its
pattern argument into a regular expression structure. This
operation is expensive, which makes string-match
inefficient if
the same regular expression is used several times (for example, in a
loop). For better performance, you can compile a regular expression in
advance and then match strings against the compiled regexp.
make-regexp
throws a
regular-expression-syntax
error.
The flag arguments change the behavior of the compiled regexp. The following flags may be supplied:
regexp/icase
regexp/newline
regexp/basic
regexp/extended
make-regexp
includes both regexp/basic
and
regexp/extended
flags, the one which comes last will override
the earlier one.
str
.
If the optional integer start argument is provided, begin matching
from that position in the string. Return a match structure describing
the results of the match, or #f
if no match could be found.
#t
if obj is a compiled regular expression, or
#f
otherwise.
Regular expressions are commonly used to find patterns in one string and replace them with the contents of another string.
port may be #f
, in which case nothing is written; instead,
regexp-substitute
constructs a string from the specified
items and returns that.
regexp-substitute
, but can be used to perform global
substitutions on str. Instead of taking a match structure as an
argument, regexp-substitute/global
takes two string arguments: a
regexp string describing a regular expression, and a target
string which should be matched against this regular expression.
Each item behaves as in regexp-substitute, with the following exceptions:
regexp-substitute/global
to recurse
on the unmatched portion of str. This must be supplied in
order to perform global search-and-replace on str; if it is not
present among the items, then regexp-substitute/global
will
return after processing a single match.
Go to the first, previous, next, last section, table of contents.