Substring in Jinja2 Pattern

When deploying with the impossible, there is 1 specific case where I need to delete the string of the final substring -p.

The line somemachine-prod-pshould be somemachine-prodonly if it -pis at the end.

The subscript function that I saw that I can use with Jinja does not meet my needs, since I need to remove the end of the line, and not start.

Ideas?

+4
source share
2 answers

Found.

If anyone wants to know:

{% if name.endswith('-p') %}
{{ name[:-2] }}
{% else %}
{{ name }}
{% endif %}
+16
source

There are more pleasant "oneliner": {{ name | regex_replace('-p$','') }}.

+17
source

Source: https://habr.com/ru/post/1667476/


All Articles