x <- "This is a URL: https://t...content-available-to-author-only...t.com/ThisIsAURL !" trimws(gsub("(https?://\\S*)|[[:punct:]]+", "\\1", x, ignore.case=TRUE))