Regex to replace a specific word
-
Hello everyone,
Let’s say I must replace “word2” on a document by “word3”, but only when the line starts by “word1”.
I’m not familiar with regex and less with regex in notepad++.
So I started do it this way and this part seems to work :
Find field ==> (?:.word1)(?:.*word2)I tried in the replace field ==> (?:.word1)(?:.*word3) but it replaced all the found lines by “(?:.word1)(?:.*word3)”
Can you please help me to do it ? Something like 10 000 files to check for several replaces needed, I’ll be mad before I end it if I have to do it manually :D
Debug info :
Notepad++ v8.4.7 (64-bit)
Build time : Nov 1 2022 - 23:31:11
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Pro (64-bit)
OS Version : 22H2
OS Build : 19045.2364
Current ANSI codepage : 1252
Plugins :
MarkdownViewerPlusPlus (0.8.2)
mimeTools (2.9)
NppConverter (4.5)
NppExport (0.4) -
I think you want this “recipe”:
https://community.notepad-plus-plus.org/topic/22690/generic-regex-replacing-in-a-specific-zone-of-textSee if you can make sense of that and how you might apply it to your situation.
-
Thanks for the link. Using this one and some others I was able to do what I wanted … almost
I wasn’t good enough to deal with all the cases only with regex and I had to modify some cases manually, not a lot fortunately.
-
@Calimero said in Regex to replace a specific word:
Using this one and some others I was able to do what I wanted … almost
I wasn’t good enough to deal with all the cases only with regex and I had to modify some cases manuallyHopefully it wasn’t a defect/limitation of the technique in the link I provided.