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


50.5 Replacing substrings

Function: irregex-replace irx str [replacements ...]
Function: irregex-replace/all irx str [replacements ...]

Match a pattern in a string, and replaces it with a (possibly empty) list of substitutions. Each replacement can be either a string literal, a numeric index, a symbol (as a named submatch), or a procedure which takes one argument (the match object) and returns a string.

irregex-replace will replace only the first match, while irregex-replace/all will replace all of them.

Examples:

(irregex-replace "[aeiou]" "hello world" "*")
⇒ "h*llo world"

(irregex-replace/all "[aeiou]" "hello world" "*")
⇒ "h*ll* w*rld"