Using RegEx in Notepad++ to delete all lines contain certain keywords?
-
I have a list of urls in a text file.
Each URL is one a new line
Example:
https://domain.com/dog.html https://domain.com/dog-2.html https://domain.com/cat.html https://domain.com/cat-2.html https://domain.com/fish.html https://domain.com/dolphin.htmlI wish to know if there is a way to use RegEx to remove all lines that contain the word cat and fish?
So the list becomes below, which removed 3 lines matched
https://domain.com/dog.html https://domain.com/dog-2.html https://domain.com/fish.html -
@NZ-Select said in Using RegEx in Notepad++ to delete all lines contain certain keywords?:
to remove all lines that contain the word cat and fish?
I believe the following (given your example) should suffice.
Using the Replace function
Find What:(?-s)^(.+)?(cat|fish)(.+)?\R?
Replace With: leave this field empty
This is a regex so search mode must be “regular expression” and have wrap around ticked.
I should mention this ONLY looks for those characters, so if the word cat or fish is part of a larger word it will still be removed. Socaterorfishermanalso get removed.Terry
-
@Terry-R said in Using RegEx in Notepad++ to delete all lines contain certain keywords?:
if the word cat or fish is part of a larger word it will still be removed
A slightly revised regex would be
Find What:^(.+)?(\bcat\b|\bfish\b)(.+)?\R?This expects non word characters (boundaries) to exist around the words
catandfish, thuscat-2is still caught.Terry
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