JavaScript / ECMAScript

GitHub Actions Expression in JS

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

Try it in the JS tester →

Pattern

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

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("\\$\\{\\{\\s*([^}]+?)\\s*\\}\\}", "g");
const input = "if: ${{ github.actor == 'octocat' }}";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

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)