Skip to content

Regex for Markdown Link

This regex matches Markdown-style links in the format [text](url). It captures both the link text and the URL in separate groups. Markdown links are used in README files, documentation, static site generators, and many content management systems. The pattern works for inline links but does not match reference-style links.

Pattern flags: g
\[([^\]]+)\]\(([^)]+)\)
Test this pattern in the Regex Tester →

What is the regex pattern for Markdown Link?

The regex pattern for Markdown Link is \[([^\]]+)\]\(([^)]+)\) with the g flag. This regex matches Markdown-style links in the format [text](url). It captures both the link text and the URL in separate groups. Markdown links are used in README files, documentation, static site generators, and many content management systems. The pattern works for inline links but does not match reference-style links. This pattern is commonly used for markdown parsing and link extraction from docs.

Test Examples

Match
[Click here](https://example.com)
Matches: [Click here](https://example.com)
Match
[Docs](./api/readme.md)
Matches: [Docs](./api/readme.md)
No Match
plain text

Common Uses

Variations

With optional title

\[([^\]]+)\]\(([^)]+?)(?:\s+"([^"]*)")?\)

Captures optional title: [text](url "title")

Reference-style

\[([^\]]+)\]\[([^\]]*)\]

Matches [text][ref] reference links

Image links

!\[([^\]]*)\]\(([^)]+)\)

Matches Markdown images ![alt](src)

Frequently Asked Questions

Does this match Markdown images?

No, Markdown images use an exclamation mark prefix: ![alt](url). Use the 'Image links' variation to match those. This pattern only matches text links.

What are reference-style links?

Reference-style links separate the link text from the URL: [text][id] with [id]: url defined elsewhere. This pattern matches inline links only. Use the 'Reference-style' variation for the other format.

Can nested brackets cause issues?

Yes, if the link text contains brackets, this simple pattern may not match correctly. For production Markdown parsing, use a dedicated library like marked, remark, or markdown-it.

Related Patterns

Markdown Heading

^(#{1,6})\s+(.+)$

URL

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]...

HTML Tag

<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>

Related Reading

Regex Cheat Sheet with Examples for Developers → URL Encoding Special Characters →