Xref: utzoo gnu.emacs.help:2361 comp.emacs:10912 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage From: sm2@sequent.cc.hull.ac.uk (Simon Marshall) Newsgroups: gnu.emacs.help,comp.emacs Subject: Anyone have a replace-regexp-region ? Message-ID: <2278.9106171549@seq.hull.ac.uk> Date: 17 Jun 91 15:49:51 GMT Sender: daemon@tut.cis.ohio-state.edu Followup-To: gnu.emacs.help Organization: Gatewayed from the GNU Project mailing list help-gnu-emacs@prep.ai.mit.edu Lines: 32 Peter A Fletcher (peterf@csis.dit.csiro.au) writes: | Hello there! I was wondering if anyone had an elisp function to replace | regexps in only the currently selected region ? It would be a really handy | thing to have around. Just rap around the replace-regexp function! Like so: (defun replace-regexp-region (regexp to-string start finish &optional delimmed) "Replace things matching REGEXP with TO-STRING in region. Preserve case in each match if case-replace and case-fold-search are non-nil and REGEXP has no uppercase letters. If called non interactively, region is specified by third and fourth args START and FINISH. Fifth arg DELIMITED (prefix arg if interactive) non-nil means replace only matches surrounded by word boundaries. In TO-STRING, \& means insert what matched REGEXP, and \ means insert what matched th \(...\) in REGEXP. Simon. " (interactive "sReplace regexp: \nsReplace regexp %s with: \nrP") (save-excursion (save-restriction (narrow-to-region start finish) (goto-char (point-min)) (perform-replace regexp to-string nil t delimmed) (message "Done")))) _______________________________________________________________________________ Simon Marshall, Dept. of Computer Science, University of Hull, Hull HU6 7RX, UK "``La la la la la la la la la'' means I love you." Email: S.Marshall@Hull.ac.uk Phone: +44 482 465951 (office) Fax: 466666