You can also use the [^\]+/.
to prevent greediness. [^/]
means "match anything expect /
, and +
repeats that one or more times..
:%s!\v^(https?)\://([^/]+)/.*$!Protocol:\1 \t Domain:\2!g
If I have /
in the regex, I will use !
as a separator so that I don't have to escape /
.
Example
Let's suppose you have the following urls:
http://academy.mises.org/courses/econgd/
http://academy.mises.org/moodle/course/view.php?id=172
http://acmsel.safaribooksonline.com/book/-/9781449358204?bookview=overview
http://acmsel.safaribooksonline.com/home
http://acordes.lacuerda.net/bebo__cigala/lagrimas_negras-2.shtml
http://acordes.lacuerda.net/jose_antonio_labordeta/albada.shtml
http://anarchitext.wordpress.com/category/new-middle-east/
https://courses.edx.org/courses/course-v1%3ADelftX%2BFP101x%2B3T2015/wiki/DelftX.FP101x.3T2015/resources-and-links/
https://cseweb.ucsd.edu/classes/wi11/cse230/lectures.html
https://developer.mozilla.org/en-US/docs/CSS
https://developers.google.com/edu/python
https://developers.google.com/structured-data/testing-tool/
Applying the substitution you would get that :
Protocol:http Domain:academy.mises.org
Protocol:http Domain:academy.mises.org
Protocol:http Domain:acmsel.safaribooksonline.com
Protocol:http Domain:acmsel.safaribooksonline.com
Protocol:http Domain:acordes.lacuerda.net
Protocol:http Domain:acordes.lacuerda.net
Protocol:http Domain:anarchitext.wordpress.com
Protocol:https Domain:courses.edx.org
Protocol:https Domain:cseweb.ucsd.edu
Protocol:https Domain:developer.mozilla.org
Protocol:https Domain:developers.google.com
Protocol:https Domain:developers.google.com
:help greedy
would have taken you to the right help topic.:help regexp
is the help describing Vim's regex flavor.