Python (re)

Markdown Image in PY

Matches Markdown image syntax ![alt](url).

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"!\[([^\]]*)\]\(([^)]+)\)")
input_text = "![logo](https://example.com/logo.png)"
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

`!\[([^\]]*)\]` captures the alt text inside brackets. `\(([^)]+)\)` captures the URL in parentheses.

Examples

Input

![logo](https://example.com/logo.png)

Matches

  • ![logo](https://example.com/logo.png)

Input

![](image.jpg) and ![alt](pic.gif)

Matches

  • ![](image.jpg)
  • ![alt](pic.gif)

Same pattern, other engines

← Back to Markdown Image overview (all engines)