I want to replace a URL in a string ("Hello world http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
") by its domain ("Hello world stackoverflow.com").
So far I was able to identify and replace the URL by some constant value but not by the URL's domain:
x <- "Hello world http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example"
gsub("http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", "URL", x)
Any help it highly appreciated.