Python (re)

Markdown Link in PY

Match Markdown links [link text](url) and capture both the display text and the URL.

Try it in the PY tester →

Pattern

regexPY
\[([^\]]+)\]\(([^)]+)\)   (flags: g)

Python (re) code

pyPython
import re

pattern = re.compile(r"\[([^\]]+)\]\(([^)]+)\)")
input_text = "[RegexPro](https://www.regexpro.dev)"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

Group 1 captures the link text inside square brackets (any chars except ]). Group 2 captures the URL inside parentheses (any chars except )).

Examples

Input

[RegexPro](https://www.regexpro.dev)

Matches

  • [RegexPro](https://www.regexpro.dev)

Input

[Click here](https://example.com/path)

Matches

  • [Click here](https://example.com/path)

Same pattern, other engines

← Back to Markdown Link overview (all engines)