Regex to Match a Markdown Link
Copy the pattern, paste your Markdown below, and watch it highlight every inline link. Below the tester: how the two capture groups give you text and URL.
Regex pattern
/\[([^\]]+)\]\(([^)]+)\)/g
This matches a Markdown link [text](url), capturing the link text in group 1 and the URL in group 2. It handles simple links but not nested brackets or reference-style links.
What this pattern matches
This matches a Markdown inline link and captures the link text in group 1 and the URL in group 2.
How it works, part by part
\[([^\]]+)\] — the square brackets and the text inside (group 1).
\(([^)]+)\) — the parentheses and the URL inside (group 2).
Limitations
It does not handle titles like [text](url "title") as a separate group, nested brackets, or reference-style links [text][ref]. It covers the common inline case.
Use it in your code
import re
text = "See the [docs](https://example.com/docs) and the [home page](https://example.com). Not a link: [broken] (spaced)."
pattern = r'''\[([^\]]+)\]\(([^)]+)\)'''
for m in re.finditer(pattern, text):
print(m.group())
const text = "See the [docs](https://example.com/docs) and the [home page](https://example.com). Not a link: [broken] (spaced).";
const re = new RegExp(String.raw`\[([^\]]+)\]\(([^)]+)\)`, "g");
console.log(text.match(re));
FAQ
How do I get the text and URL separately?
Use the capture groups: group 1 is the text, group 2 is the URL.
Does it match reference-style links?
No. This matches inline [text](url) links only, not [text][ref] style.