I have such a snippets:

Exercise 2.32.  We can represent a set as a list of distinct elements, and we can represent the set of all subsets of the set as a list of lists. For example, if the set is (1 2 3), then the set of all subsets is (() (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3)). Complete the following definition of a procedure that generates the set of subsets of a set and give a clear explanation of why it works:

(define (subsets s)
  (if (null? s)
      (list nil)
      (let ((rest (subsets (cdr s))))
        (append rest (map <??> rest)))))

enter image description here

Select them all and run regex-replace ^\(.*(\) → : \1

The result I expected is

enter image description here

Nevertheless, it proved to be:

enter image description here

Whats' the problem with my usage?

1 Answer 1


. matches any single character except a newline, so ^.*( matches from line beginning till (, thus all lines besides the empty line matches. Don't forget the first line contains (:

Exercise 2.32.  ... For example, if the set is (1 2 3), ...

You should change . into \s- (it matches any whitespace character, you can also just use space character).

However, I always use C-x r t (M-x string-rectangle) to prepend a common prefix to multiple lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.