GitHub Actions Expression in GO
Match `${{ expression }}` interpolations used in GitHub Actions workflow YAML.
Try it in the GO tester →Pattern
regexGO
\$\{\{\s*([^}]+?)\s*\}\} (flags: g)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\$\{\{\s*([^}]+?)\s*\}\}`)
input := `if: ${{ github.actor == 'octocat' }}`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
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 publishMatches
${{ secrets.NPM_TOKEN }}
Input
no expressionsNo match
—