Regex patterns/Text & extraction
Markdown link
Two captures — the label and the target — with negated classes instead of lazy dots.
/\[([^\]]+)\]\(([^)]+)\)/gThe problem
Pull the label and the URL out of markdown links so you can rewrite or list them.
How it reads
Follow the line from left to right — every path you can trace is a string this pattern matches.
\[([^\]]+)\]\(([^)]+)…In order:\[The character "["([^\]]+)Capture group 1:[^\]]+Any character except "]", one or more times, as many as possible\]The character "]"\(The character "("([^)]+)Capture group 2:[^)]+Any character except ")", one or more times, as many as possible\)The character ")"
Matches
- [the docs](https://example.com/docs)
- [home](/)
Does not match
- plain text
- [unclosed(https://x)
- not a [link] here
Where it bites
- A negated class ([^\]]+) says "anything up to the closing bracket" directly. A lazy .+? gets the same answer by backtracking, which is slower and harder to reason about.
- Nested brackets in the label, and parentheses inside the URL, both defeat it — markdown allows them and this pattern cannot.
- Image syntax () matches too, since the leading ! is not excluded.