Regular Expressions 101

Improvement on Python Print substitution argument matching

1

Regular Expression
Python

r"
(?:(?:{)|(?:%\())([^:\)}]*)(?:(?:(?::.)?})|(?:\).))
"
gm

Description

Get the python substitution strings from inside of print statements. Replace the whole substitution string with {{ ArgumentName }} for use in a Jinja2 rendering.

Supports

  • fstrings
  • old style format strings %(argument)d
Submitted by Giles Knap - 9 months ago