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
| Token | Description |
|---|---|
| \[ | 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 . Those would require separate patterns.
Example Test Strings
| Input | Expected |
|---|---|
| [Google](https://google.com) | Match |
| [Click here](./page) | Match |
| [empty]() | No Match |
| plain text | No Match |
| [API docs](/api/v1) | Match |
Try It — Interactive Tester
Match Highlighting(3 matches)
Matches & Capture Groups
23 charsFlags: gMatches: 3Ctrl+Shift+C to copy regex