| Allegro CL version 10.0 Unrevised from 9.0 to 10.0. 9.0 version |
Arguments: string regexp substitution &key count (start 0) end case-fold single-line multiple-lines ignore-whitespace
This function replaces substrings in string that matches regexp with substitution, returning the new string. It always returns a new string, even if no substitutions are made.
regexp can be a string that specifies a regular expression, or an already-compiled (by compile-re) regular expression. regexp should match a non-zero length string, or an error is signaled.
substitution can be a string, or a function that takes one argument, a list of match substrings returned by the regexp matcher. The function must return a string, which is then used as a substitution string.
The keyword argument count limits the maximum
number of substitutions. If it is nil
, all
occurrences of regexp in
string are replaced.
The keyword arguments start and end limit the region in string where matching occurs.
Other keyword arguments are passed to compile-re to compile regexp.
The symbol naming this operator is also exported from the regexp package.
cl-user(14): (replace-re ":f" "(\\W)(\\w)" "\\1 \\2") ": f" cl-user(15): (replace-re "00a1b23c99" "\\d+" "#") "#a#b#c#" cl-user(16): (replace-re "12345" "\\d(\\d+)(\\d)" "#\\1.\\2") "#234.5" cl-user(17): (replace-re "12345" "\\d(?<middle>\\d+)(?<tail>\\d)" "#\\k<middle>.\\k<tail>") "#234.5" cl-user(18): (replace-re "a12345b67890c" "\\d(?<middle>\\d+)(?<tail>\\d)" "#\\k<middle>.\\k<tail>") "a#234.5b#789.0c" cl-user(19): (replace-re "0123456789" "\\d+" (lambda (matches) (format nil "(~a)" (length (car matches))))) "(10)" cl-user(20): (replace-re "a12345b678c90" "\\d+" (lambda (matches) (format nil "(~a)" (length (car matches))))) "a(5)b(3)c(2)" cl-user(21): (replace-re "a12345b678c90" "([a-z])(\\d+)" (lambda (matches) (format nil "~a(~a)" (string-upcase (cadr matches)) (length (caddr matches))))) "A(5)B(3)C(2)" cl-user(22):
See The new regexp2 module in regexp.htm for further information on this function and the regexp2 module.
Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 9.0 page.
Created 2015.5.21.
| Allegro CL version 10.0 Unrevised from 9.0 to 10.0. 9.0 version |