Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 1.0k Views
    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 SelectN Offline
      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 RT Offline
        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 RT Offline
          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

          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors