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.html
    

    I 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. So cater or fisherman also 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 cat and fish, thus cat-2 is still caught.

    Terry


Log in to reply