| Allegro CL version 8.2 Unrevised from 8.1 to 8.2. 8.1 version |
Arguments: string regexp to-string &rest args &key count start end newlines-special case-fold shortest &allow-other-keys
Replace occurrences of regexp in
string with to-string.
Regular expression groups in regexp can be
referenced with \n in to-string. If
count is nil
or t
, replace all occurrences; if a number,
replace that number of occurrences.
This function accepts all the following match-regexp keywords: newlines-special, case-fold, shortest, start and end, and passes them to match-regexp (used for finding the matches in string). Note that using start and end might be rather inefficient if used repeatedly on a large string, since for each call to replace-regexp, a new string will be created.
Use of this function is deprecated and it is maintained for backward compatibility only. See regexp.htm for information on the newer regular expression compiler in Allegro CL. You should use the functionality described there instead of this function is new code.
Examples:
(replace-regexp "xxx yyy zzz xxx yyy zzz" "xxx" "yyy") RETURNS "yyy yyy zzz yyy yyy zzz" (replace-regexp "xxx yyy zzz xxx yyy zzz" "xxx" "RR") RETURNS "RR yyy zzz RR yyy zzz" (replace-regexp "123 yyy zzz 123 yyy zzz 123" "y" "WHY") RETURNS "123 WHYWHYWHY zzz 123 WHYWHYWHY zzz 123" (replace-regexp "xxx yyy zzz xxx yyy zzz xxx" "xxx" "yyy" :start 3 :end 20) RETURNS "xxx yyy zzz yyy yyy zzz xxx" (replace-regexp "xxx yyy zzz xxx yyy zzz xxx" "xxx" "RR" :start 3 :end 20) RETURNS "xxx yyy zzz RR yyy zzz xxx" (replace-regexp "xxx yyy zzz xxx yyy zzz xxx" "xxx" "yyy" :start 3 :end 23) RETURNS "xxx yyy zzz yyy yyy zzz xxx" (replace-regexp "123 yyy zzz 123 yyy zzz 123" "123" "yyy" :start 3 :end 27) RETURNS "123 yyy zzz yyy yyy zzz yyy" (replace-regexp "123 yyy zzz 123 yyy zzz 123" "123" "9999" :start 3 :end 27) "123 yyy zzz 9999 yyy zzz 9999" ;; Here is a more complicated example that extracts some ;; fields out of a standard Unix passwd entry: (replace-regexp "joe:*:512:50:Joe User:/home/joe:/bin/csh" "^\\([^:]*\\):[^:]*:\\([0-9]*\\):[0-9]*:\\([^:]*\\):.*$" "Login {\\1} Full Name {\\3} UID {\\2}") RETURNS "Login {joe} Full Name {Joe User} UID {512}" ;; Here is is in action: (with-open-file (f "/etc/passwd") (loop repeat 5 as entry = (read-line f nil nil) while entry collect (replace-regexp entry "^\\([^:]*\\):[^:]*:\\([0-9]*\\):[0-9]*:\\([^:]*\\):.*$" "Login {\\1} Full Name {\\3} UID {\\2}"))) RETURNS ("Login {root} Full Name {system PRIVILEGED account} UID {0}" "Login {+} Full Name {} UID {0}" "Login {daemon} Full Name {system background account} UID {1}" "Login {bin} Full Name {system librarian account} UID {3}" "Login {uucp} Full Name {UNIX-to-UNIX Copy} UID {4}")
Copyright (c) 1998-2016, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 8.1 page.
Created 2010.1.21.
| Allegro CL version 8.2 Unrevised from 8.1 to 8.2. 8.1 version |