Search and Replace - Remove specific IP ranges
-
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, ::1Here 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.1Thanks for your time
-
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 ModetoRegular 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
\bmatches a “word border” (that is, the border between a word character and a non-word character) \S*matches zero or more non-whitespace characters\x20matches a normal space character.
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