Skip to content

Instantly share code, notes, and snippets.

@adamcbrewer
Created March 20, 2013 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcbrewer/5204018 to your computer and use it in GitHub Desktop.
Save adamcbrewer/5204018 to your computer and use it in GitHub Desktop.
JS: Strip protocols
/**
* Strips protocols off strings.
* Usefull for ensuring a consistent base where user input is involved.
*
* Matches:
* http://
* https://
* ftp://
* mailto:
* www.
* @
*
* @author Adam Brewer - @adamcbrewer - adamcbrewer.com
*
* Usage: "http://test.com".stripProtocol();
*
*/
String.prototype.stripProtocol = function () {
return this.replace(/(www\.|@|mailto\:|(ht|f)tp(s?)\:\/\/)/gm, '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment