Skip to content

Instantly share code, notes, and snippets.

@noel9999
Last active August 29, 2015 14:13
Show Gist options
  • Save noel9999/45c081f96c308f65c11e to your computer and use it in GitHub Desktop.
Save noel9999/45c081f96c308f65c11e to your computer and use it in GitHub Desktop.
js regExp 練習
var text = 'there are a lot of great websites like www.missingmanuals.com and http://www.noelsaga.com'
var urlRegex = /((\bhttps?:\/\/)|(\bwww\.))\S*/g
var url = text.match(urlRegex)
console.log(url[0])
console.log(url[1]);
//看看兩者的差異
var text2 = 'my website is www.noelsaga.com'
var urlRegex2 = /((\bhttps?:\/\/)|(\bwww\.))\S*/
var url2 = text2.match(urlRegex2)
console.log(url2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment