Jinja2: Difference between revisions

From PedrosBrainDump
Created page with "== Check a pattern on a string == === Check by a pattern on the beginning of a string === {% if my_string.startswith('pattern') %}{% endif %} {% if my_string[:len('pattern')] == 'pattern' %}{% endif %} === Check by a pattern on the end of a string === === Check by a pattern into a string ==="
 
 
Line 8: Line 8:


=== Check by a pattern on the end of a string ===
=== Check by a pattern on the end of a string ===
{% if my_string.endswith('pattern') %}{% endif %}
{% if my_string[-len('pattern'):] == 'pattern' %}{% endif %}


=== Check by a pattern into a string ===
=== Check by a pattern into a string ===
{% if 'pattern' in my_string %}{% endif %}

Latest revision as of 03:29, 10 November 2024

Check a pattern on a string

Check by a pattern on the beginning of a string

{% if my_string.startswith('pattern') %}{% endif %}
{% if my_string[:len('pattern')] == 'pattern' %}{% endif %}

Check by a pattern on the end of a string

{% if my_string.endswith('pattern') %}{% endif %}
{% if my_string[-len('pattern'):] == 'pattern' %}{% endif %}

Check by a pattern into a string

{% if 'pattern' in my_string %}{% endif %}