Skip to main content
Code & Markup · In-Browser Regular Expression Lab

Markdown Link Regex — Extract [Anchor Text](URL) Pairs

Captures anchor text and target URL from Markdown link syntax `[text](url)`.

Flags:
//g
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:[Castov](https://castov.com)

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

[Castov](https://castov.com) Pass
[Documentation](https://castov.com/tools) Pass

Expected Invalid Samples (Must Reject)

plain text Rejected (Pass)
[unclosed link Rejected (Pass)
https://example.com Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /\[([^\]]+)\]\((https?:\/\/[^\s\)]+)\)/g;
const text = "[Castov](https://castov.com)";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Group 1 captures the human-readable link text; Group 2 captures the web hyperlink. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
\[([^\]]+)\]Link Text GroupCaptures everything inside square brackets.
\((https?:\/\/[^\s\)]+)\)URL GroupCaptures HTTP/HTTPS web address inside parentheses.

Frequently Asked Questions

Does this match internal relative links?
To allow relative links like `/convert`, use `\[([^\]]+)\]\(([^\s\)]+)\)`.
Browse All 40 Patterns