Skip to content

Instantly share code, notes, and snippets.

@ahgood
Created October 29, 2019 19:25
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 ahgood/085f7052acc88cfae324955dc3dcde04 to your computer and use it in GitHub Desktop.
Save ahgood/085f7052acc88cfae324955dc3dcde04 to your computer and use it in GitHub Desktop.
Extract URLs from content
const regxURL = new RegExp(`(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])`, 'igm');
const content = 'Hello www.google.com World http://yahoo.com';
const urls = content.match(regxURL); // ["www.google.com", "http://yahoo.com"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment