Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a file with a number of urls in the form:

I'd like to extract the sitehost of the url and append it to the end of the line:

Any idea how to do that?

share|improve this question

One way to do that:

:s:\(.*//\)\([^/]*\)\(/.*\):\1\2\3 \2:


  • :s: - Using substitution
  • \(.*//\) - Capture the part up to the double slash (group 1)
  • \([^/]*\) - Capture everything that's not a slash (group 2)
  • \(/.*\) - Capture the first single slash and everything after it (group 3)
  • :\1\2\3 \2: - Output groups 1, 2 and 3 followed by a space and group 2 again


You could sorten that to:

:s:\(.*//\)\([^/]*\)\(/.*\):& \2:

The ampersand outputs the whole matched string which includes the whole line since the regex begins and ends with .*. You could use \0 instead of the ampersand.

share|improve this answer
And is there an output group that contains the whole line in which there was a match? – sumek Feb 28 '11 at 13:52
@sumek: Please see my edited answer. – Dennis Williamson Feb 28 '11 at 14:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.