Notepad++ regex group capture

notepad++, regex

Solution

This works without look around:

Find: `[a-zA-Z0-9-.]+\.([a-zA-Z0-9-]+)\.([a-zA-Z0-9-]+)$` Replace: `\1\.\2`

It finds something with at least 2 periods and only letters, numbers, and dashes following the last two periods; then it replaces it with the last 2 parts. More intuitive, in my opinion.

There's something funny going on with that leading `xxx`. It doesn't appear to be plain ASCII. For the sake of this question, I'm going to assume that's just something funny with this site and not representative of your real data.

Incorrect

Interestingly, I previously had an incorrect answer here that accumulated a lot of upvotes. So I think I should preserve it:

Find: `[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+)\.(.+)$` Replace: `\1\.\2`

It just finds a host name with at least 2 periods in it, then replaces it with everything after the first dot.

Problem

I have such txt file: ``` ххх.prontube.ru salo.ru bbb.antichat.ru yyy.ru xx.bb.prontube.ru zzz.com srfsf.jwbefw.com.ua ``` Trying to delete all subdomains with such regex: ``` Find: .+\.((.*?)\.(ru|ua|com\.ua|com|net|info))$ Replace with: \1 ``` Receive: ``` prontube.ru salo.ru antichat.ru yyy.ru prontube.ru zzz.com com.ua ``` Why last line becomes `com.ua` instead of `jwbefw.com.ua` ?

Original source