Regex to Match Markdown Links

Match Markdown hyperlinks with this regex pattern. Captures both the display text and destination URL from [text](url) link syntax. Free tool.

Regular Expression

/\[([^\]]+)\]\(([^)]+)\)/g

Token Breakdown

TokenDescription
\[Matches a literal opening bracket
(Start of capturing group
[^\]]Negated character class — matches any character NOT in \]
+Matches the preceding element one or more times (greedy)
)End of group
\]Matches a literal closing bracket
\(Matches a literal opening parenthesis
(Start of capturing group
[^)]Negated character class — matches any character NOT in )
+Matches the preceding element one or more times (greedy)
)End of group
\)Matches a literal closing parenthesis

Detailed Explanation

This regex matches Markdown-style links in the format text. Here is the token-by-token breakdown:

[ — Matches a literal opening square bracket. Square brackets are regex metacharacters (character class delimiters), so the backslash escapes it.

([^]]+) — A capturing group matching the link text. The character class [^]] matches any character except a closing square bracket, and the + requires at least one character. This captures everything between the square brackets as the link display text.

] — Matches a literal closing square bracket.

( — Matches a literal opening parenthesis. Parentheses are regex metacharacters (group delimiters), so the backslash escapes it.

([^)]+) — A capturing group matching the URL. The character class [^)] matches any character except a closing parenthesis, and the + requires at least one character. This captures everything between the parentheses as the link destination.

) — Matches a literal closing parenthesis.

The g flag enables global matching to find all Markdown links in the text. Group 1 contains the link text and group 2 contains the URL. This pattern matches links like Google, Click here, and API docs.

This regex is widely used in Markdown parsers, static site generators, and content management systems. It handles standard Markdown links but does not match reference-style links like [text][id] or image syntax like alt. Those would require separate patterns.

Example Test Strings

InputExpected
[Google](https://google.com)Match
[Click here](./page)Match
[empty]()No Match
plain textNo Match
[API docs](/api/v1)Match

Try It — Interactive Tester

//g
gimsuy

Match Highlighting(3 matches)

[Google](https://google.com) [Click here](./page) [empty]() plain text [API docs](/api/v1)

Matches & Capture Groups

#1[Google](https://google.com)index 0
Group 1:Google
Group 2:https://google.com
#2[Click here](./page)index 29
Group 1:Click here
Group 2:./page
#3[API docs](/api/v1)index 71
Group 1:API docs
Group 2:/api/v1
Pattern: 23 charsFlags: gMatches: 3

Ctrl+Shift+C to copy regex

Customize this pattern →