Regex template functions
These template functions let you search, match, and transform text with regular expressions. Use them when you need to extract specific parts of a string, validate formats, or replace patterns in sensor values.
Home Assistant extends the Jinja2 template engine with many custom functions, filters, and tests. Each function on this page has its own page with detailed descriptions, parameters, and practical examples.
New to templates? Start with the templating documentation to learn the basics.
-
Test if string es pattern
matchTemplate test that checks if a string matches a regular expression at the beginning. -
Find all regex matches
regex_findallFinds all occurrences of a regular expression pattern in a string and returns them as a list. -
Find regex match at index
regex_findall_indexFinds all occurrences of a regex pattern and returns the match at a specific index. -
Match a regex pattern
regex_matchTests if a string matches a regular expression pattern at the beginning. -
Replace using a regex pattern
regex_replaceReplaces all occurrences of a regular expression pattern in a string. -
Search for a regex pattern
regex_searchSearches for a regular expression pattern anywhere in a string. -
Test if string contains pattern
searchTemplate test that checks if a string contains a regular expression pattern anywhere.