JavaScript Template Literal Placeholder
Match `${expression}` placeholders inside JavaScript template literals.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\$\\{([^{}]+)\\}", "g");
const input = "`Hello ${name}, you have ${count} items`";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\$\{([^{}]+)\}")
input_text = "`Hello ${name}, you have ${count} items`"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\$\{([^{}]+)\}`)
input := "`Hello ${name}, you have ${count} items`"
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\$\{([^{}]+)\} (flags: g)Raw source: \$\{([^{}]+)\}
How it works
Examples
Input
`Hello ${name}, you have ${count} items`Matches
${name}${count}
Input
const url = `https://api.com/${endpoint}?key=${apiKey}`Matches
${endpoint}${apiKey}
Input
no placeholdersNo match
—Common use cases
- •Static analysis of template-literal usage
- •Tagged template processors and i18n tooling
- •Linters that detect unsanitized expressions in HTML templates
- •Build-time string interpolation tooling
Related patterns
Python f-String Expression
Text ProcessingMatch `{expression}` placeholders inside Python f-strings (or any single-brace template syntax).
JavaScript Variable Declaration
Text ProcessingMatch JavaScript / TypeScript variable declarations (`var`, `let`, `const`), capturing the keyword and identifier name.
JSON Boolean / Null Literal
Text ProcessingMatch JSON `true`, `false`, and `null` literal values, with word boundaries to avoid partial matches.
Emoji (Unicode)
Text ProcessingMatch emoji characters across the main Unicode emoji ranges — requires the Unicode flag in JavaScript.