Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Using RegEx in Notepad++ to delete all lines contain certain keywords?

    Help wanted · · · – – – · · ·
    2
    3
    194
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NZ Select
      NZ Select last edited by

      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
      
      1 Reply Last reply Reply Quote 0
      • Terry R
        Terry R last edited by Terry R

        @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

        1 Reply Last reply Reply Quote 3
        • Terry R
          Terry R last edited by

          @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

          1 Reply Last reply Reply Quote 3
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors