1

Sorry guys for a very simple question, but I couldn't find the correct way to replace the last octet (is this the correct word for it) with a "0".

So far I tried several things, after searching these forums, but or it replaces 1 number (not 1, 2 or 3 numbers after the last dot).

Here are 3 examples:

1.1.1.1
22.22.22.22
333.333.333.333

In all these cases the last (.1, .22 or .333) need to replaced with a 0. Reason for this is I want to put these annoying IP's who try to access SSH in a block list permantly.

So far all solutions I found don't give a correct result. Maybe someone has a working regex for Notepad++ to do this?

Thanks in advance.

1
  • I want to put these annoying IP's who try to access SSH in a block list permantly i think you make a mistake. Most part of Internet nodes have a mask which differs from /24. You may block excess addresses. Including addresses which may not be blocked - for example, public or commercial proxies, or eved datacenters which hosts such nodes.
    – Akina
    Dec 19 '19 at 17:10
3

It's much more efficient without capture groups:

  • Ctrl+H
  • Find what: \d+$
  • Replace with: 0
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

\d+         # 1 or more digits
$           # end of line

Screen capture (before):

enter image description here

Screen capture (after):

enter image description here

2
  • 1
    Applicable if each line contais IP address only. But, given that this is a list of IP-addresses, it's a smart decision.
    – Akina
    Dec 19 '19 at 17:08
  • 1
    Nice clean and detailed solution. This solution is nicer imho therefor accepting this one as answer. TY!
    – Joanne
    Dec 20 '19 at 8:19
5
Find: ((\d{1,3}.){3})\d{1,3}
Replace: \10
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.