Community
    • Login

    Search and Replace - Remove specific IP ranges

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 1.1k Views 1 Watching
    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.
    • Cranky PennyC Offline
      Cranky Penny
      last edited by PeterJones

      Fellow Notepad++ Users,

      Could you please help me the the following search-and-replace problem I am having?

      I have rows of IP addresses with multiple IPs listed and I need to remove all entries in every row that begin with 172.* 128.* or fe*

      Here is the data I currently have (“before” data):

      172.16.0.1, 156.1.1.1, 127.0.0.1, fe20::250:90fd:fec5:7a2d, ::1
      172.16.0.1, 172.1.1.1, 10.1.1.1, 127.0.0.1, fe20::250:90fd:fec5:7a2d, ffe20::250:90fd:fec5:7a2d, fe20::250:90fd:fec5:7a2d, ::1
      172.15.0.1, 10.1.1.1, 127.0.0.1, fe20::250:90fd:fec5:7a2d, ::1
      172.15.0.1, 10.1.1.1, 127.0.0.1, fe20::250:90fd:fec5:7a2d, ::1
      172.12.0.1, 172.1.1.1, 10.1.1.1, 127.0.0.1, fe20::250:90fd:fec5:7a2d, ::1
      

      Here is how I would like that data to look (“after” data):

      156.1.1.1
      10.1.1.1
      10.1.1.1
      10.1.1.1
      10.1.1.1
      

      Thanks for your time

      1 Reply Last reply Reply Quote 0
      • Mark OlsonM Offline
        Mark Olson
        last edited by

        What you say you want doesn’t quite match what you appear to want, based on your before and after.

        In any case, this should work:

        • go to the find/replace form (Ctrl+H assuming normal keybindings)
        • set the Search Mode to Regular expression

        Find what: (?-i)(?:\b(?:(?:172|12[78])\.|ff?e)\S*,\x20*)|,\x20::1
        Replace with: nothing (leave that box empty).

        You’ll have to hit the Replace All button twice.

        This isn’t really a particularly clever or complex regular expression, although it may appear daunting. Some notes:

        • the (?-i) makes the regex case-sensitive
        • the (?: and matching ) are just grouping parentheses that don’t capture
        • the \b matches a “word border” (that is, the border between a word character and a non-word character)
        • \S* matches zero or more non-whitespace characters
        • \x20 matches a normal space character.
        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