Regex Help Wanted - Delete all lines containing "STRING"
-
I have an output file created by program A that is then read by program B.
Program A generates and appends each file with “System Tag ID-DD/MM/YYYY”, these files can be in batches of 10 -> 1000
Program B does not appreciate this “erroneous” data so throws a wobbly when the file is imported.
I have no control over the source code for either program so cannot either of them to play nice.
Using N++, how would I go about using a regex to find each line containing the string “System Tag” then deleting that line in every open file?
I’ve been googling and found a few methods but none of them seem to search past the first line or return the results needed, so im obviously missing something huge
for example I found this on this community but adapting it fails to find any results (?i-s)^.MeX.\R (It is supposed to find each line containing MeX in any case and replace the line with BLANK when replace is used
Thank guys
-
how would I go about using a regex to find each line containing the string “System Tag” then deleting that line in every open file?
Search for:
(?-is)^.*?System Tag.*\Rand replace with nothing.
Use the Replace All in All Opened Documents button. -
Can I suggest the “Sed” utility?
sed “/Regex/d” InFile > OutFile
“d” deletes the line containing the Regex.
Alternatively : sed -i “/Regex/d” FileName - “-i” changes the <file> in place.
Also : sed -i -r (extended Regex)
I use a .bat that requests the Input and Output file names, copies the Input file to the Output file and then does lots of substitutions. However Sed then creates a temporary file “Sedxxx” for each command which then need deleting.
If you have many files, you can create a DOS .bat file to process all files within a folder using the “FOR” command.
WIndows 7, Sed for windows. -
@Phillip-Stanhope said in Regex Help Wanted - Delete all lines containing "STRING":
Can I suggest the “Sed” utility?
You can, but really people are coming here looking for solutions to problems with the solutions involving Notepad++.
Directing them to non-Notepad++ utilities, when there are ways to do what they are requesting within Notepad++, is considered bad form and off-topic.
-
@Alan-Kilborn Thanks for this alan, but think i’m missing something and just can’t get this to work. I have included a screenshot for the exact method im using and it still returns no results in the “replace” dialog box.
Do you have any ideas where I could be going wrong?

-
@Gary-Smith said in Regex Help Wanted - Delete all lines containing "STRING":
Do you have any ideas where I could be going wrong?
Your last line, which is the one that has
System Tagon it, does not have a newline sequence, so\Rhas nothing to match.(?-is)^.*?System Tag.*(\R|\z)should work (see “Anchors” in the usermanual regex section) -
@PeterJones said in Regex Help Wanted - Delete all lines containing "STRING":
(?-is)^.?System Tag.(\R|\z)
Worked flawlessly , thanks a lot folks for all your help, just saves me a whole bunch of work :)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login