comparison lispref/searching.texi @ 65122:04a0656bc67c

(Search and Replace): Add replace-regexp-in-string.
author Richard M. Stallman <rms@gnu.org>
date Thu, 25 Aug 2005 11:05:31 +0000
parents 3e6c73954fda
children 54da3e88d8f6 2d92f5c9d6ae
comparison
equal deleted inserted replaced
65121:64ac61f4b3b4 65122:04a0656bc67c
1145 1145
1146 @node Search and Replace 1146 @node Search and Replace
1147 @section Search and Replace 1147 @section Search and Replace
1148 @cindex replacement 1148 @cindex replacement
1149 1149
1150 @defun replace-regexp-in-string regexp rep string &optional fixedcase literal subexp start
1151 This function copies @var{string} and searches it for matches for
1152 @var{regexp}, and replaces them with @var{rep}. It returns the
1153 modified copy. If @var{start} is non-@code{nil}, the search for
1154 matches starts at that index in @var{string}, so matches starting
1155 before that index are not changed.
1156
1157 This function uses @code{replace-match} to do the replacement, and it
1158 passes the optional arguments @var{fixedcase}, @var{literal} and
1159 @var{subexp} along to @code{replace-match}.
1160
1161 Instead of a string, @var{rep} can be a function. In that case,
1162 @code{replace-regexp-in-string} calls @var{rep} for each match,
1163 passing the text of the match as its sole argument. It collects the
1164 value @var{rep} returns and passes that to @code{replace-match} as the
1165 replacement string. The match-data at this point are the result
1166 of matching @var{regexp} against a substring of @var{string}.
1167 @end defun
1168
1150 @defun perform-replace from-string replacements query-flag regexp-flag delimited-flag &optional repeat-count map start end 1169 @defun perform-replace from-string replacements query-flag regexp-flag delimited-flag &optional repeat-count map start end
1151 This function is the guts of @code{query-replace} and related 1170 This function is the guts of @code{query-replace} and related
1152 commands. It searches for occurrences of @var{from-string} in the 1171 commands. It searches for occurrences of @var{from-string} in the
1153 text between positions @var{start} and @var{end} and replaces some or 1172 text between positions @var{start} and @var{end} and replaces some or
1154 all of them. If @var{start} is @code{nil} (or omitted), point is used 1173 all of them. If @var{start} is @code{nil} (or omitted), point is used