Q:

IPv4 address search using regular expression in Notepad++

I am trying to sanitize a configuration file in notepad++.
Basically, I need to find and replace the IPv4 address with regular expression and replace only first two octet, I tried with following regular expression to search for IPV4, however didnt work in notepad++
\b(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(.(?1)){3}\b

Could anyone please help ?

A:

Your regex \b(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(.(?1)){3}\b captures the first octet in group 1, then matches the 2nd and 3rd octet and captures the fourth octet in group 2.
To replace the first 2 octets you want to match the first 2 octets and capture the last 2 octets to keep them in the replacement.
What you could do it to match all 4 octects using (?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d) for an octet and capture the last 2 including the leading dot for the third octet and the replace with X.X followed by capturing group 1.
Find
\b(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))\b
Replace with
X.X\1

