| Allegro CL version 6.2 Unrevised from 6.1 |
Arguments: string regexp to-string &rest args &key count start end &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.
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 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}") "Login {joe} Full Name {Joe User} UID {512}" ;; Here is is in action: Here it 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}"))) ("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-2002, Franz Inc. Oakland, CA., USA. All rights reserved.
Documentation for Allegro CL version 6.2. This page was not revised from the 6.1 page.
Created 2002.2.26.
| Allegro CL version 6.2 Unrevised from 6.1 |