I've defined a function that is supposed to iterate over an alist, and use the CAR and CDR of each element in the list to populate the regexp in re-search-forward
and the replacement string in replace-match
, respectively. Here is what I have:
(defun search-and-replace ()
(let ((alist '(("regexp" "replacement-str")
...)))
(dolist (search-pair alist)
(point-min)
(while (re-search-forward (car search-pair) nil t)
(replace-match (cdr search-pair))))))
This returns an error: Wrong type argument: stringp, ("replacement-str")
. What am I missing?
Edit:
Thanks for the help. Here's what I ended up with:
(defun search-and-replace (alist)
(save-excursion
(goto-char (point-min))
(dolist (search-pair alist)
(while (re-search-forward (car search-pair) nil t)
(replace-match (cdr search-pair)))
(goto-char (point-min))))
Where each item in ALIST
is a cons cell of ("regexp" . "replacement-string")
.