On Tue, Nov 10, 2020 at 02:40:08PM +0100, Christopher Dimech wrote: > I now have got 'rec-cont', which lets me pass a string. > How can I add a dafault if I don't pass a regex in the > mini-buffer. > > (defun rec-cont (beg end regex) > (interactive "r\ns rec-cont regex: ") > (replace-regexp "^" regex nil beg end)) > ;; (replace-regexp "^" ";; + " nil beg end)) But watch out: the replacement string (confusingly called `regex' here, others have already pointed that out) might contain special sequences (e.g. "\\&") which have a meaning in this context. If doing that from a program, better not use `replace-regexp' but do it yourself in a loop along this lines: (while (search-forward-regexp "^" nil 'noerror) (replace-match replacement-string)) (I've taken the liberty to rename the replacement string `replacement-string'). The doc explicitly warns against using `replace-regexp' in programs: "This function is for interactive use only; in Lisp code use `re-search-forward' and `replace-match' instead." Cheers - t