regex fails to match ^, $, \b in multiline mode

Hi,
I’m studying how to use regexp, and just follow documented examples,
{{ ‘foo\nBAR’ | regex_search(“^bar”, multiline=True, ignorecase=True) }}

expected result is: “bar”.
Instead of “bar” it gets an empty string.
Is it a bug, or do I miss an important setting?

Thanks,
Dennis

See https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html
#searching-strings-with-regular-expressions

and pay careful attention to details such as punctuation and case:

1. The example is:
{{ 'foo\nBAR' | regex_search('^bar', multiline=True, ignorecase=True) }}
instead, you used:
{{ 'foo\nBAR' | regex_search("^bar", multiline=True, ignorecase=True) }}

2. The expected result is:
# => 'BAR'
whereas you say:
expected result is: "bar".

Try exactly what the example shows, and let us know if it does not produce
what the example should produce.

Antony.

Hi,

BTW, ansible-2.9.24-2.el7.

“bar” instead of “BAR” was just a mistype.
Double quote instead of single quote plays no role, i.e. this YAML:

  • hosts: monitor1p
    tasks:

  • debug:
    msg: Debug> {{ ‘foo\nBAR’ | regex_search(‘^bar’, multiline=True, ignorecase=True) }}

produces same output:

ok: [monitor1p] => {
“msg”: "Debug> "
}

Regards,

понедельник, 30 августа 2021 г. в 11:50:44 UTC+3, Antony Stone:

You need to quote the entire jinja expression itself (including the
curlies) if you use it as a yaml value.
Because the single quotes are already using inside the expression,
you;'d have to use the double quotes:

  tasks:
    - debug:
        msg: "Debug> {{ 'foo\nBAR' | regex_search('^bar',
multiline=True, ignorecase=True) }}"