JavaScript / ECMAScript

Markdown Link in JS

Match Markdown links [link text](url) and capture both the display text and the URL.

Try it in the JS tester →

Pattern

regexJS
\[([^\]]+)\]\(([^)]+)\)   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("\\[([^\\]]+)\\]\\(([^)]+)\\)", "g");
const input = "[RegexPro](https://www.regexpro.dev)";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

Group 1 captures the link text inside square brackets (any chars except ]). Group 2 captures the URL inside parentheses (any chars except )).

Examples

Input

[RegexPro](https://www.regexpro.dev)

Matches

  • [RegexPro](https://www.regexpro.dev)

Input

[Click here](https://example.com/path)

Matches

  • [Click here](https://example.com/path)

Same pattern, other engines

← Back to Markdown Link overview (all engines)