Skip to content

Instantly share code, notes, and snippets.

@offby1
Created December 1, 2009 17:22
Show Gist options
  • Save offby1/246451 to your computer and use it in GitHub Desktop.
Save offby1/246451 to your computer and use it in GitHub Desktop.
(defun replace-in-matching-lines (sought-re old-re new)
(interactive "sMatch lines containing:\nsOld regexp:\nsReplacement:")
(while (re-search-forward sought-re (point-max) t)
(save-restriction
(narrow-to-region (line-beginning-position)
(line-end-position))
(goto-char (point-min)) ;i.e., beginning of line
(while (re-search-forward old-re (point-max)
t)
(replace-match new)))
(goto-char (line-end-position))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment