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

  • Do you want to delete the whole line up to the WARN? – A_P Feb 15 at 16:26
  • @A_P Yes , I want to delete whole line BEFORE word WARN – a_subscriber Feb 15 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. – A_P Feb 15 at 17:07
  • @A_P I known about multi cursors. I use them. But I want to solve this task by regexp. – a_subscriber Feb 15 at 17:17
  • emacs must be doing something under the covers. none of these solutions work stackoverflow.com/questions/2013124/… – A_P Feb 15 at 17:35
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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