Regex for Matching a Markdown Link

Captures the link text and URL from Markdown link syntax.

Published October 12, 2026

This regex matches Markdown links [text](url) and captures the text and URL.

How the pattern works

Breaking the pattern down: \[([^\]]+)\] = link text in brackets; \(([^)\s]+)\) = URL in parentheses.

Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.

Pattern tests

/\[([^\]]+)\]\(([^)\s]+)\)/
✓ '[Docs](https://example.com)'
✓ '[a](b)'
✗ '[text] (url)'
✗ 'plain text'

Practical examples

The pattern

const re = /\[([^\]]+)\]\(([^)\s]+)\)/

Test it

const re = /\[([^\]]+)\]\(([^)\s]+)\)/
re.test('[Docs](https://example.com)')   // true
re.test('[a](b)')   // true
re.test('[text] (url)')   // false
re.test('plain text')   // false

In Python

import re
re.search(r'\[([^\]]+)\]\(([^)\s]+)\)', text)

Common mistakes

  • Nested brackets or parentheses in URLs.
  • Images with ! prefix.
  • Using regex for complex Markdown parsing.

Key takeaways

  • Anchors (^ and $) make the whole string match instead of a part of it.
  • Regex checks format only; verify data separately when it matters.
  • Test with valid and invalid samples.

FAQ

Use a parser?

For real Markdown, use a library like marked.

Where can I test this pattern?

Use the Regex Tester on this site, or regex101.com.

More General articles