Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In general, you can delete text that matches a given regexp by using the empty string <code>""</code> as the replacement in the two functions you mention. However, as others mentioned in the comments above, your regular expression is faulty.</p> <p>For instance, if your buffer contains the following text:</p> <pre><code>1. My todo list 1.1. Brush teeth 1.2. Floss 2. My favorite movies 2.1. Star Wars episodes 4-6 </code></pre> <p>and you would like to get rid of the numbers at the beginning of each line, you could place the cursor at the beginning of the buffer and then type <code>M-C-%</code> (that is, you press at a time: ALT, CTRL, Shift, 5) to invoke the command <code>query-replace-regexp</code>. You'll get asked two parameters in the minibuffer, first the regexp to match than the replacement string. So, in our example, you could use the following regexp:</p> <pre><code>\([0-9]\.\)+\s- </code></pre> <p>as the first parameter, and simply hit ENTER for the second parameter, i.e., don't specify anything as the replacement. That way, the replacement is the empty string: you replace what ever matches the regexp with nothing.</p> <p><code>query-replace-regexp</code> will ask you interactively for every match if you want to replace it or if you want to skip it. This is the "query"-part in <code>query-replace-regexp</code> and it is helpful to see if the regexp you came up with actually matches what you thought it does. If you're sure it does, you can type <code>!</code> to make Emacs replace the remaining matches without asking every time.</p> <p>If you use <code>M-x replace-regexp</code> instead of <code>M-C-%</code> Emacs will replace every match without asking for input at every match.</p> <p>For the special case that you'd like to delete whole lines when a certain part of the line matches a regexp, there's also <code>delete-matching-lines</code> and its evil, goatee-wearing twin brother from a parallel universe <code>delete-non-matching-lines</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload