Next: , Previous: , Up: irregex   [Index]


50.7 Miscellaneous functions

Function: irregex-split irx str
Function: irregex-split irx str start end
Function: irregex-extract irx str
Function: irregex-extract irx str start end

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.

Function: irregex-fold irx kons knil str [finish start past]

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))))
Function: irregex-quote str

Return a new string with any special regular expression characters escaped, to match the original string literally in POSIX regular expressions.

Function: irregex-opt list-of-strings

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.

Function: sre->string sre

Convert an SRE to a POSIX–style regular expression string, if possible.


Next: , Previous: , Up: irregex   [Index]