1

emacs 26.1, windows 10

I have some text. I need to replace all text before WARN

enter image description here

I use:

  1. query-replace-regexp: .*WARN

  2. query replace regexp: RET

But I need to delete all text BEFORE WARN. How I can do this?

here is the result: enter image description here

5
  • Do you want to delete the whole line up to the WARN? Commented Feb 15, 2019 at 16:26
  • @A_P Yes , I want to delete whole line BEFORE word WARN Commented Feb 15, 2019 at 16:57
  • may I suggest few alternative solutions: 1. You can define a keyboard macro as follows: C-x ( C-s WARN Ent M-b C-Space C-a C-w C-x ) This will give a macro that does what you need for first occurring line with WARN. Then just C-u 50 C-x e to do the same macro 50 times. 2. install multiple-cursors (and you should anyways) select WARN and then do mc/select-next-like-this (bind it to something easy) keep selecting and then just edit all lines with WARN as if you were editing a single line. Commented Feb 15, 2019 at 17:07
  • @A_P I known about multi cursors. I use them. But I want to solve this task by regexp. Commented Feb 15, 2019 at 17:17
  • emacs must be doing something under the covers. none of these solutions work stackoverflow.com/questions/2013124/… Commented Feb 15, 2019 at 17:35

1 Answer 1

1

To remove the text before WARN, just enter WARN as the replacement text. That is, use WARN as your input to the second prompt.

5
  • @A_P: I don't understand; sorry. Commented Feb 15, 2019 at 17:23
  • *WARN does not work. Try it, you'll see. I don't understand how the answer got accepted. Commented Feb 15, 2019 at 17:45
  • .*WARN, not *WARN. Commented Feb 16, 2019 at 1:27
  • blind as a bat. Sorry for the confusion. It does the job. Commented Feb 18, 2019 at 19:55
  • @A_P: No problem; and thanks for confirming. A prefix of . is very easy to not notice. Commented Feb 18, 2019 at 20:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.