2

I have list of domain names such as:

i.gr-assets.com
instacam.com
r4---sn-bg0e7n7r.googlevideo.com

I want to remove the top level domain names. My output should look like in the below format:

i.gr-assets
instacam
r4---sn-bg0e7n7r.googlevideo

Please note that I need to remove multiple top level domains and not just .com as my small example shows so I'm looking for a way to replace all that I specify I need to have removed and not just one.

How can I do this using Notepad++?

  • 3
    Using the Ctrl+H option go to the Replace tab and then put .com in the "Find What" field and have <nothing leave it blank> in the "Replace With" field and set the Wrap Around check, the Regular Expression checked (normal mode would work too) and select "Replace All". See if that does it by testing. Here's an image of the options: i.imgur.com/RheE0jf.png – Pimp Juice IT Aug 9 '17 at 15:35
  • It's also worth noting that any replacements you do can be done successively while recording a macro for future re-use. – Anaksunaman Aug 9 '17 at 16:00
  • not only for .com. Like this, I have so many top level domain names. In a text file, in each domain name, i want to remove the top level domain name. But here some domain names has more than one full stop – vinayakumar R Aug 9 '17 at 17:56
  • @vinayakumarR See the Multiple String Replacement section I added to my answer since you clarified what you needed was to remove more than just one top level domain and you only provided a small simple example in your question. Let me know how that goes when you get to it. – Pimp Juice IT Aug 9 '17 at 19:36
  • You should update your sample list with different extensions and edge cases. Why would you want to do it with Notepad++ specifically? – simlev Aug 9 '17 at 19:43
1

Single String Replacement

Here's how I did it with Notepad++ using the Ctrl+H option and then by replacing .com with <nothing leaving it blank> and the other options set as listed below in the screen shot. This will work with the Search Mode set to Regular Expression or as Normal Search too by the way.

Instructions

  1. Press Ctrl+H in Notepad++
  2. Put .com in the Find what field
  3. Leave the Replace with field empty with nothing nor any white space
  4. Be sure the Wrap around option is checked
  5. Select either the Regular expression or the Normal option within the Search Mode section
  6. Press the Replace All option

enter image description here

Before

i.gr-assets.com
instacam.com
r4---sn-bg0e7n7r.googlevideo.com

After

i.gr-assets
instacam
r4---sn-bg0e7n7r.googlevideo

Multiple String Replacement

Here's how I did it with Notepad++ using the Ctrl+H option and then by replacing (.com|.net|.biz|.uk) top level domains separated by pipes within the parenthesis just like that and replace those with <nothing leaving it blank> and the other options set as listed below in the screen shot. This will only work with the Regular Expression option.

Instructions

  1. Press Ctrl+H in Notepad++
  2. Put (.com|.net|.biz|.uk) in the Find what field
    • Your top level domains will each be separated by a pipe symbol (|) within the parenthesis—this tells it to match all strings within the parenthesis separated by a pipe
  3. Leave the Replace with field empty with nothing nor any white space
  4. Be sure the Wrap around option is checked
  5. Select the Regular expression option within the Search Mode section
  6. Press the Replace All option

enter image description here

Before

i.gr-assets.com
instacam.com
r4---sn-bg0e7n7r.googlevideo.com
i.gr-assets.net
instacam.net
r4---sn-bg0e7n7r.googlevideo.net
i.gr-assets.biz
instacam.biz
r4---sn-bg0e7n7r.googlevideo.biz
i.gr-assets.uk
instacam.uk
r4---sn-bg0e7n7r.googlevideo.uk

After

i.gr-assets
instacam
r4---sn-bg0e7n7r.googlevideo
i.gr-assets
instacam
r4---sn-bg0e7n7r.googlevideo
i.gr-assets
instacam
r4---sn-bg0e7n7r.googlevideo
i.gr-assets
instacam
r4---sn-bg0e7n7r.googlevideo
| improve this answer | |
  • not only for .com. Like this, I have so many top level domain names. In a text file, in each domain name, i want to remove the top level domain name. But here some domain names has more than one full stop – – vinayakumar R Aug 9 '17 at 17:56
  • What with "domain names has more than one full stop"? You'd need a list of existing TLDs. – simlev Aug 9 '17 at 19:40
  • @simlev That's how I provided it for the OP and I assume you want the Op to read that comment though but each TLD will need to be specified in the regex for sure so that's how I provided the answer as I know how to complete that task with the Notepad++ app. Vinayakumar - I'm assuming this is what you need and not something to populate all TLDs automatically so you will need to specify those as I wrote in the answer above. I apologize if there's something I'm missing (from either one of you). Respectfully~ – Pimp Juice IT Aug 9 '17 at 19:45
1

Considering that your list has one URL per line. You could use this regular expression to remove the TLD's:

[.][^.]*$

Like this:

enter image description here

| improve this answer | |

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.