diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 7909572bede..b024c8f2656 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -1459,6 +1459,8 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): self.globals["urlencode"] = urlencode self.globals["max"] = max self.globals["min"] = min + self.tests["match"] = regex_match + self.tests["search"] = regex_search if hass is None: return diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 0e8b2f76843..46098917b0e 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -1003,6 +1003,17 @@ def test_regex_match(hass): assert tpl.async_render() is True +def test_match_test(hass): + """Test match test.""" + tpl = template.Template( + r""" +{{ '123-456-7890' is match('(\\d{3})-(\\d{3})-(\\d{4})') }} + """, + hass, + ) + assert tpl.async_render() is True + + def test_regex_search(hass): """Test regex_search method.""" tpl = template.Template( @@ -1038,6 +1049,17 @@ def test_regex_search(hass): assert tpl.async_render() is True +def test_search_test(hass): + """Test search test.""" + tpl = template.Template( + r""" +{{ '123-456-7890' is search('(\\d{3})-(\\d{3})-(\\d{4})') }} + """, + hass, + ) + assert tpl.async_render() is True + + def test_regex_replace(hass): """Test regex_replace method.""" tpl = template.Template(