Delete all lines containing word1 and word2
Posted: 26 Apr 2024, 08:56
What is the code for RegExReplace that deletes all lines containing both word 1 and word 2 and does the same as the code below?
How can I replace this code with a RegExReplace expression?
A big thank for your help in advance!
How can I replace this code with a RegExReplace expression?
Code: Select all
Text := "
(
Here is a line with a lot of text.
Here is a line with the word often used.
This line has little content.
Another line with often and much.
One further line without matching words.
Example line with often and much.
)"
Word1 := "often"
Word2 := "much"
; Split the text into lines
Lines := StrSplit(Text, "`n")
; Iterate through each line
NewText := ""
Loop, % Lines.MaxIndex()
{
Line := Lines[A_Index]
; Check if the line contains both word1 and word2
if !(InStr(Line, Word1) && InStr(Line, Word2))
{
; Add the line to the new text if both words are not present
NewText .= Line "`n"
}
}
; Output the result
MsgBox % NewText