18

I'm using Notepad++ Replace box to delete text to the left of the colon (:) in all 3 lines of my file:

TRACE: do

TRACE: re

TRACE: mi

I'm using ^[^:]+: in the 'Find what:' field and 'Replace with:' is empty but when it goes to the next line it automatically selects and deletes what was output in the previous line, so when I run Replace All it results in:

mi

It should show:

do

re

mi

22

It's a "bug" ("feature") of Notepad++, you have to capture the rest of the line and use the value in replace:

  • Find what: ^[^:]+:(.+)$
  • Replace with: $1
  • check Wrap around
  • check Regular expression
  • UNCHECK . matches newline
  • Replace all

Another way is:

  • Find what: ^[^:\r\n]+:
  • Replace with: LEAVE EMPTY
  • 5
    +1. Originally, I though NP++'s implementation was fine, but I tested this Python example, and found that NP++ is indeed irregular by retaining position after a lookbehind is evaluated. Learn something new every day! I lack time now, but I can probably file an issue in their GitHub repo later (there's no related issue currently open). – Graham Apr 2 at 14:27
  • 3
    Not to mention that it's misleading because it's inconsistent with other components of the find-and-replace tab, like what's shown to the user when previewing a change via the "Find" or "Mark". (Side note: I find "Mark" to be particularly useful when drafting regex to ensure I haven't made a silly mistake.) Really I'm starting to think I should switch text editors or start contributing my own bug fixes to Notepad++, since there are actually a surprising number of miscellaneous issues. But I guess that's probably the case for any dedicated program user like myself. – Graham Apr 2 at 14:56
  • 3
    I like the second approach better -- it looks like it should work in almost any "altered implementation" of regex interpretation. – Carl Witthoft Apr 2 at 17:43
  • 2
    Even shorter, by using a reluctant quantifier: Replace ^.*?: with empty. (Docs) – Nayuki Apr 2 at 18:46
  • This has to be a bug. ^[^:]*?: and ^.*?: should do exactly the same thing, but they don't. ^[^:\r\n]*?: does work correctly though, so I'd guess that's where the issue is, somehow. The same issue occurs with ^.*?: if you check the ". matches newline" box. – Yay295 Apr 3 at 5:40

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.