comparison lisp/subr.el @ 28148:0f14966fe791

(replace-regexp-in-string): Renamed from replace-regexps-in-string. Doc fix.
author Dave Love <fx@gnu.org>
date Tue, 14 Mar 2000 22:57:28 +0000
parents 093dcd5f39b2
children 763c6639628b
comparison
equal deleted inserted replaced
28147:02f9ade0908d 28148:0f14966fe791
1194 (setq i (1- i)) 1194 (setq i (1- i))
1195 (if (eq (aref newstr i) fromchar) 1195 (if (eq (aref newstr i) fromchar)
1196 (aset newstr i tochar))) 1196 (aset newstr i tochar)))
1197 newstr)) 1197 newstr))
1198 1198
1199 (defun replace-regexps-in-string (regexp rep string &optional 1199 (defun replace-regexp-in-string (regexp rep string &optional
1200 fixedcase literal subexp start) 1200 fixedcase literal subexp start)
1201 "Replace all matches for REGEXP with REP in STRING. 1201 "Replace all matches for REGEXP with REP in STRING.
1202 1202
1203 Return a new string containing the replacements. 1203 Return a new string containing the replacements.
1204 1204
1205 Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the 1205 Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the
1209 REP is either a string used as the NEWTEXT arg of `replace-match' or a 1209 REP is either a string used as the NEWTEXT arg of `replace-match' or a
1210 function. If it is a function it is applied to each match to generate 1210 function. If it is a function it is applied to each match to generate
1211 the replacement passed to `replace-match'; the match-data at this 1211 the replacement passed to `replace-match'; the match-data at this
1212 point are such that match 0 is the function's argument. 1212 point are such that match 0 is the function's argument.
1213 1213
1214 To replace a single match, make REGEXP match up to \\'." 1214 To replace only the first match (if any), make REGEXP match up to \\'
1215 and replace a sub-expression, e.g.
1216 (replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1)
1217 => \" bar foo\"
1218 "
1215 1219
1216 ;; To avoid excessive consing from multiple matches in long strings, 1220 ;; To avoid excessive consing from multiple matches in long strings,
1217 ;; don't just call `replace-match' continually. Walk down the 1221 ;; don't just call `replace-match' continually. Walk down the
1218 ;; string looking for matches of REGEXP and building up a (reversed) 1222 ;; string looking for matches of REGEXP and building up a (reversed)
1219 ;; list MATCHES. This comprises segments of STRING which weren't 1223 ;; list MATCHES. This comprises segments of STRING which weren't