Regular Expressions 101

Community Patterns

1...56789...400

Markdown Images (alt text, link, description)

0

Regular Expression
Python

r"
(?:[!]\[(?P<caption>.*?)\])\((?P<image>.*?)(?P<description>\".*?\")?\)
"
gm

Description

Extract images in a Markdown text, matching 3 named groups:

  • caption = alternate text
  • image = link (URL or relative)
  • description = text

Kind of syntax

![](image_url)
![alternative text](image_url)
![](image_url "description")
![alternative text](image_url "description")

Useful for Mkdocs.

Derived from https://regex101.com/r/ypjBSA/1

Submitted by GeoJulien - a year ago