const regex = /\[([\s\S]*?)\]\(((?:http(?:s)?:\/\/.)?(?:[\w]+\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{1,63}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=\(\)]*))\)/g; const markdown = "[Google](https://www.google.com) is a search engine. [Wikipedia](https://en.wikipedia.org/wiki/Main_Page) is an online encyclopedia."; let match; while ((match = regex.exec(markdown)) !== null) { const linkText = match[1]; const linkUrl = match[2]; console.log(`Link text: ${linkText}`); console.log(`Link URL: ${linkUrl}`); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter