url.go 523 B

123456789101112131415161718
  1. package misspell
  2. import (
  3. "regexp"
  4. )
  5. // Regexp for URL https://mathiasbynens.be/demo/url-regex
  6. //
  7. // original @imme_emosol (54 chars) has trouble with dashes in hostname
  8. // @(https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?$@iS
  9. var reURL = regexp.MustCompile(`(?i)(https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+(/[^\s]*)?`)
  10. // StripURL attemps to replace URLs with blank spaces, e.g.
  11. // "xxx http://foo.com/ yyy -> "xxx yyyy"
  12. func StripURL(s string) string {
  13. return reURL.ReplaceAllStringFunc(s, replaceWithBlanks)
  14. }