Regex_search ignoring ignorecase

Iโ€™m using the following code to convert strings to emoticons on my Apple Watch.
This code has worked a few years ago, but now it no longer does.

Iโ€™m using the Template tab in the Developer tools.

{% if not is_state('sensor.recycleapp_tomorrow', 'None') %} 
{{ ['Ma ','Di ','Wo ','Do ','Vr ','Za ','Zo '][(now().weekday()+1)%7] +  states('sensor.recycleapp_tomorrow') | regex_replace(find='pmd', replace='๐Ÿฅซ', ignorecase=False)  | regex_replace(find='restafval', replace='๐Ÿ—‘๏ธ', ignorecase=False) | regex_replace(find='papier', replace='๐Ÿ“ฐ', ignorecase=False) | regex_replace(find='glas', replace='๐Ÿพ', ignorecase=False) | regex_replace(find='kerstbomen', replace='๐ŸŽ„', ignorecase=False) | regex_replace(find=',', replace='', ignorecase=False) }} 
{% elif not is_state('sensor.recycleapp_today', 'None') %} 
{{ ['Ma ','Di ','Wo ','Do ','Vr ','Za ','Zo '][now().weekday()] + states('sensor.recycleapp_today') | regex_replace(find='pmd', replace='๐Ÿฅซ', ignorecase=False)  | regex_replace(find='restafval', replace='๐Ÿ—‘๏ธ', ignorecase=False) | regex_replace(find='papier', replace='๐Ÿ“ฐ', ignorecase=False) | regex_replace(find='glas', replace='๐Ÿพ', ignorecase=False) | regex_replace(find='kerstbomen', replace='๐ŸŽ„', ignorecase=False) | regex_replace(find=',', replace='', ignorecase=False) }} 
{% endif %}

The result is the following:
image

So itโ€™s definitely not find-replacing.

However, when I change the code to resemble the case of the sensor states:

{% if not is_state('sensor.recycleapp_tomorrow', 'None') %} 
{{ ['Ma ','Di ','Wo ','Do ','Vr ','Za ','Zo '][(now().weekday()+1)%7] +  states('sensor.recycleapp_tomorrow') | regex_replace(find='PMD', replace='๐Ÿฅซ', ignorecase=False)  | regex_replace(find='Restafval', replace='๐Ÿ—‘๏ธ', ignorecase=False) | regex_replace(find='Papier', replace='๐Ÿ“ฐ', ignorecase=False) | regex_replace(find='Glas', replace='๐Ÿพ', ignorecase=False) | regex_replace(find='Kerstbomen', replace='๐ŸŽ„', ignorecase=False) | regex_replace(find=',', replace='', ignorecase=False) }} 
{% elif not is_state('sensor.recycleapp_today', 'None') %} 
{{ ['Ma ','Di ','Wo ','Do ','Vr ','Za ','Zo '][now().weekday()] + states('sensor.recycleapp_today') | regex_replace(find='PMD', replace='๐Ÿฅซ', ignorecase=False)  | regex_replace(find='Restafval', replace='๐Ÿ—‘๏ธ', ignorecase=False) | regex_replace(find='Papier', replace='๐Ÿ“ฐ', ignorecase=False) | regex_replace(find='Glas', replace='๐Ÿพ', ignorecase=False) | regex_replace(find='Kerstbomen', replace='๐ŸŽ„', ignorecase=False) | regex_replace(find=',', replace='', ignorecase=False) }} 
{% endif %}

It is find-replacing.
image

Any suggestions on why the ignorecase is not working?

ignorecase=False means it must match the supplied string exactly. That means this will only match pmd and nothing else (it will not match Pmd, PMD, etc).

regex_replace(find='pmd', replace='๐Ÿฅซ', ignorecase=False)

Example

If you change it to ignorecase=True then it will match the supplied string regardless if the stringโ€™s letters are uppercase or lowercase.

1 Like

I mixed up True/False.
Sorry, feeling stupid now :slight_smile:

No worries; we all make mistakes.

Before you go, please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topicโ€™s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.