Regular Expressions 101

Community Patterns

Community Library Entry

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 - 2 years ago