Notepad ++ regexp to search and replace with exceptions

I am new to regexp and I would like to know how to search and replace for the following case:

The file contains many occurrences of the following elements:

L1234_XL3.ext 

as well as many occurrences:

 L1234_XL3 

I just want to find and replace L1234_XL3 occurrences using XL3 without affecting instances with the extension.

I use notepad ++ to execute a regular expression.

+4
source share
2 answers

If Notepad ++ supports lookaheads, you can simply use L1234_XL3(?!\.ext) to search and "XL3" to replace.

EDIT: It doesn't seem to support lookaheads after all. A pity; you have to do it in a complicated way without regular expressions (regexen?):

  • Replace L1234_XL3.ext with QQQ (or any other line that does not appear in the file)
  • Replace L1234_XL3 with XL3.
  • Replace QQQ with L1234_XL3.ext.
+4
source

Step 1. Change all occurrences of L1234_XL3.ext to L-1-2-3-4_XL3.ext (for example)

Step 2. Change all occurrences of L1234_XL3 to XL3

Step 3. Change all occurrences of L-1-2-3-4_XL3.ext back to L1234_XL3.ext

As far as I understand, Notepad ++ 5.4.5 does not support positive browsing

+2
source

Source: https://habr.com/ru/post/1299083/


All Articles