Python (re)

GitHub Actions Expression in PY

Match `${{ expression }}` interpolations used in GitHub Actions workflow YAML.

Try it in the PY tester →

Pattern

regexPY
\$\{\{\s*([^}]+?)\s*\}\}   (flags: g)

Python (re) code

pyPython
import re

pattern = re.compile(r"\$\{\{\s*([^}]+?)\s*\}\}")
input_text = "if: ${{ github.actor == 'octocat' }}"
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

\$\{\{ matches the literal `${{`. \s*([^}]+?)\s* lazily captures the inner expression (with surrounding whitespace stripped). \}\} matches the closing `}}`. The lazy quantifier prevents accidentally consuming through to a later `}}` in the same line.

Examples

Input

if: ${{ github.actor == 'octocat' }}

Matches

  • ${{ github.actor == 'octocat' }}

Input

run: echo ${{ secrets.NPM_TOKEN }} | npm publish

Matches

  • ${{ secrets.NPM_TOKEN }}

Input

no expressions

No match

Same pattern, other engines

← Back to GitHub Actions Expression overview (all engines)