Closed MeganerdDev closed 4 months ago
To provide context from testing on this:
env = Environment(loader=DictLoader({'template': '''
{% for interface in interfaces %}
{% if regex_search(interface.name, 'GigabitEthernet\d\/0\/\d+') and interface.mode == 'ACCESS' %}
match found.
{% endif %}
{% endfor %}
'''}))
env = Environment(loader=DictLoader({'template': '''
{% macro regex_search_macro(value, pattern) %}
{{ value | regex_search(pattern) }}
{% endmacro %}
{% for interface in interfaces %}
{% if regex_search_macro(interface.name, 'GigabitEthernet\d\/0\/\d+') and interface.mode == 'ACCESS' %}
match found.
{% endif %}
{% endfor %}
'''}))
This needs to be flipped:
{% if interface.name | regex_search('GigabitEthernet\d\/0\/\d+') and interface.mode == 'ACCESS' %}
becomes
{% if 'GigabitEthernet\\d/0/\\d+' | regex_search(interface.name) and interface.mode == 'ACCESS' %}
pretty confident that is the issue, but feel free to open back up if need to.
Environment
Expected Behavior
The expectation is that the
netutils.regex.regex_search
will return a match, same asre.regex_search
Observed Behavior
When using the
netutils.regex.regex_search
filter from the provided Jinja example the regular expression is not finding a match, howeverre.regex_search
is working directly. At closer inspection, I can see the issue is the order of the string and regex parameters are flipped. When flipping the order to matchre.regex_search
everything works as expected.From python we can specify the arguments directly so this is not an issue there. However when trying to use this from Jinja we do run in to this issue.
Steps to Reproduce