Full link Markdown regex

PHOTO EMBED

Wed Apr 19 2023 09:54:16 GMT+0000 (Coordinated Universal Time)

Saved by @Mhdaljuboori

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}`);
}
content_copyCOPY