Find all regex matches: regex_findall
The regex_findall template filter finds all occurrences of a regular expression (regex) pattern in a string and returns them as a list. A regular expression is a special text pattern that lets you describe what you are looking for. While regex_search just tells you whether a pattern exists, regex_findall collects every match and gives them all back to you.
This is useful when you need to extract multiple pieces of data from a text value. For example, you might want to pull all numbers out of a sensor’s state string, extract all IP addresses from a log message, or collect all entity IDs mentioned in a text attribute. The result is a list, so you can count the matches, loop through them, or pick a specific one by index.
Usage
Here’s how to use this template function. Copy any example and adjust it to your setup.
{{ "Living room 23.5C, Bedroom 19.8C" | regex_findall("\\d+\\.\\d+") }}
['23.5', '19.8']
Function signature
The signature is a technical summary of this template function. It shows the name of the function, the values (called parameters) it accepts, and what type of data each parameter expects (for example, a piece of text or a number).
Function parameters that have a = with a value after them are optional. If you leave them out, the default value shown is used automatically. Function parameters without a default are required.
regex_findall(
value: str,
find: str = "",
ignorecase: bool = False,
) -> list[str]
Function parameters
The following parameters can be provided to this function.
Counting matches
Since the result is a list, you can use the length filter to count how many matches were found.
{{
"error at 10:15, error at 11:30, error at 12:45"
| regex_findall("error") | length
}}
3
Good to know
- Returns an empty list when nothing matches, not
Noneor an error. - Capturing groups change the output: with one group, you get strings; with multiple groups, you get tuples.
- A literal dot in the pattern must be escaped as
\., since.matches any character in regex.
Try it yourself
Ready to test this? Open Developer tools > Template, paste the example into the Template editor, and watch the result update on the right. Edit the values to see how the function adapts to your own entitiesAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more].
More examples
Real scenarios where this function comes up in automations and templates. Copy any example and adapt it to your setup.
Extract all numbers from a sensor state
Pull every number out of a text-based sensor value for processing.
{% set values = "Power: 150W, Voltage: 230V, Current: 0.65A"
| regex_findall("\\d+\\.?\\d*") %}
{{ values }}
['150', '230', '0.65']
List all matching words
Find all words in a string that start with a capital letter.
{{ "The Living Room Light is On" | regex_findall("[A-Z][a-z]+") }}
['The', 'Living', 'Room', 'Light', 'On']
Loop through extracted values
Extract all temperature values from a multi-sensor string and display them.
{% set temps = "Kitchen 21C, Hall 19C, Office 22C"
| regex_findall("(\\w+) (\\d+)C") %}
{% for room, temp in temps %}
{{ room }}: {{ temp }}C
{% endfor %}
Kitchen: 21C
Hall: 19C
Office: 22C
Still stuck?
The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with your template and expected result, or share on our subreddit /r/homeassistant.
AI assistants like ChatGPT or Claude can also explain or fix templates when you describe what you want in plain language.
Related template functions
These functions work well alongside this one:
-
Find regex match at index: regex_findall_index - Finds all occurrences of a regex pattern and returns the match at a specific index.
-
Match a regex pattern: regex_match - Tests if a string matches a regular expression pattern at the beginning.
-
Search for a regex pattern: regex_search - Searches for a regular expression pattern anywhere in a string.
-
Replace using a regex pattern: regex_replace - Replaces all occurrences of a regular expression pattern in a string.