Next: irregex pcre, Previous: irregex chunk, Up: irregex [Index]
irregex-split
splits the string str into substrings divided
by the pattern in irx. irregex-extract
does the opposite,
returning a list of each instance of the pattern matched disregarding
the substrings in between.
This follows the API for regexp-fold
from SCSH. The
kons procedure takes the following signature:
(kons <from-index> <match> <seed>)
where ?from-index
is the index from where we started
searching (initially start and thereafter the past index of the
last match); ?match
is the resulting match data object;
?seed
is the accumulated fold result starting with
knil.
The rationale for providing the ?from-index
is because this
information is useful (e.g. for extracting the unmatched portion of the
string before the current match, as needed in irregex-replace
),
and not otherwise directly accessible.
The optional finish takes two arguments:
(finish <from-index> <seed>)
which simiarly allows us to pick up the unmatched tail of the string,
and defaults to just returning the ?seed
.
start and past select a substring of str.
To extract all instances of a match out of a string, we can use:
(map irregex-match-substring (irregex-fold <irx> (lambda (i m s) (cons m s)) '() <str> (lambda (i s) (reverse s))))
Return a new string with any special regular expression characters escaped, to match the original string literally in POSIX regular expressions.
Return an optimized SRE matching any of the literal strings in
the list, like Emacs’ regexp-opt
. Note this optimization does
not help when irregex
is able to build a DFA.
Convert an SRE to a POSIX–style regular expression string, if possible.
Next: irregex pcre, Previous: irregex chunk, Up: irregex [Index]