Apr
13
2012
Here is a simple JavaScript RegEx pattern for extracting any URL that begins with http:
<script type="text/javascript">
// example string, looks like a tweet to me :)
var str="Awesome resources for HTML5! http://bit.ly/palermo4html5 #HTML5";
// UPDATED 2012-07 thanks to ArthurDent69!
// could also be written as:
// var regexUrl = new RegExp("https?:[^\s]+", "gi");
var regexUrl=/https?:[^\s]+/gi;
// if a match is found, the return type is an array of matches
document.write(str.match(regexUrl));
// output of above line of code:
// http://bit.ly/palermo4html5
</script>