Regular Expression For Gvim Remove Duplicate Domains

I need a regular expression written to use in gVim (can be downloaded here: http://www.vim.org/download.php

I have a list of over 6,000,000 URLs in a .txt file (which opens in gVim for editing).

The URLs are in this format (random):

http://www.example.com/some-url.php
http://example2.com/another_url.html
http://example3.com/
http://www.example4.com/anotherURL.htm
http://www.example.com/some-url2.htm
http://example.com/some-url3.html
http://www.example2.com/somethingelse.php
http://example5.com

In other words, there is no specific format to the URLs. Some have the WWW, some don’t, they all have different formats.

I need a regular expression written for gVim that will remove all duplicate DOMAINs from the list (and it’s corresponding URL), leaving behind the first instance it finds.

So it would take the example list posted above, and the output file should look like this:

http://www.example.com/some-url.php
http://example2.com/another_url.html
http://example3.com/
http://www.example4.com/anotherURL.htm
http://example5.com

Here are two nice sites that explain how to use regular expressions within gVim pretty nicely:

http://147.188.192.43/documentation/tutorials/docsystem/build/tutorials/gvim/gvim.html#Vi-Regular-Expressions

http://www.softpanorama.org/Editors/Vimorama/vim_regular_expressions.shtml

Leave a Reply

Your email address will not be published. Required fields are marked *