Created
January 22, 2012 16:49
-
-
Save andyedinborough/1657642 to your computer and use it in GitHub Desktop.
One RegExp to match urls, email addresses, Twitter usernames and hashtags.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function combine() { | |
var ret = '', flags = ''; | |
[ ].forEach.call(arguments, function (exp) { | |
exp = exp.toString(); | |
if (exp[0] !== '/') { | |
flags = exp; | |
} else { | |
ret += exp.substr(1, exp.length - 2); | |
} | |
}); | |
return new RegExp(ret, flags); | |
} | |
var rxALL = combine(/(?=\w)/, | |
/*Email *//([a-z0-9_\-\.]+@(?:[a-z0-9\-]+\.)+[a-z\-]+)|/, | |
/*URL *//((?:(?:https?\:\/\/)?(?:[a-z0-9\-]+\.)+[a-z]{2,3}(?!\w))(?:[\S]*[a-z0-9\/=&])?)|/, | |
/*Username *//(@[a-z0-9_]+)|/, | |
/*Tag *//(#[a-z0-9_]{2,})/, | |
/(?!\w)/, 'gi'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rxALL = /(?=\w)([a-z0-9_\-\.]+@(?:[a-z0-9\-]+\.)+[a-z\-]+)|((?:(?:https?\:\/\/)?(?:[a-z0-9\-]+\.)+[a-z]{2,3}(?!\w))(?:[\S]*[a-z0-9\/=&])?)|(@[a-z0-9_]+)|(#[a-z0-9_]{2,})(?!\w)/gi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment