Using regex_replace in automation actions doesn't work

Hi,

I’m trying this little code in the developer tools, and I get a result:

{{ states('sensor.p2000_brandweer_amsterdam') |regex_replace(find='\d{6}', replace='', ignorecase=False) }}

However, when I put this in an action, it won’t save. When I delete the pipe including the regex_replace sentence, it works, but without the intended outcome of course.

service: tts.google_translate_say
data:
  entity_id: media_player.google_nest_audio_woonkamer
  language: nl
  message: "{{ states('sensor.p2000_brandweer_amsterdam') |regex_replace(find='\d{6}', replace='', ignorecase=False) }}"

In this topic I see a similar solution which seems to work, but that’s not a dynamic state: Regex in automation action not working

Allright, I had an epiphany and ended up using this:

message: >
    {% set outcome = states('sensor.p2000_brandweer_amsterdam')
    |regex_replace(find='\d{6}', replace='', ignorecase=False)
    | replace("BR", "Brand",1)
    | replace("P", "PRIO",1)%} 
    "P2000 brandweer: {{ outcome }}"

Try it this way:

message: '{{ states("sensor.p2000_brandweer_amsterdam") |regex_replace(find="d{6}", replace="", ignorecase=False) }}'