Text Processingflags: g
Python f-String Expression
Match `{expression}` placeholders inside Python f-strings (or any single-brace template syntax).
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
\{([^{}]+)\} (flags: g)Raw source: \{([^{}]+)\}
How it works
\{ matches the literal opening brace. ([^{}]+) captures one or more characters that are NOT another brace — this avoids accidentally matching `{{` (the literal-brace escape in f-strings) and prevents nested-brace headaches. \} matches the closing brace.
Examples
Input
f"Hello {name}, you are {age} years old"Matches
{name}{age}
Input
f"Total: {amount:.2f} USD"Matches
{amount:.2f}
Input
f"escaped {{ not a placeholder }}"No match
—Common use cases
- •Static analysis of f-string usage
- •Linting for unsafe expressions in templates
- •Translating f-strings to .format() during downgrades
- •Generating docs from template files
Related patterns
Triple-Quoted String (Python / TS)
Text ProcessingMatch triple-quoted strings (Python docstrings, TypeScript triple-quote, etc.) including newlines.
JavaScript Template Literal Placeholder
Text ProcessingMatch `${expression}` placeholders inside JavaScript template literals.
Base64 String
Text ProcessingMatch Base64-encoded strings, including proper padding with = and == characters.
Python Import Statement
Text ProcessingMatch Python `import x` and `from x import y` statements, capturing the module and target.