ansible.builtin.regex_escape filter – escape regex chars

Note

This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name regex_escape. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.regex_escape for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

New in Ansible 2.8

Synopsis

  • Escape special characters in a string for use in a regular expression.

Input

This describes the input of the filter, the value before | ansible.builtin.regex_escape.

Parameter

Comments

Input

string / required

String to escape.

Positional parameters

This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | ansible.builtin.regex_escape(positional1, positional2, ...)

Parameter

Comments

re_type

string

Which type of escaping to use.

Choices:

  • "python" ← (default)

  • "posix_basic"

Notes

Note

  • posix_extended is not implemented yet

Examples

# safe_for_regex => '\^f\.\*o\(\.\*\)\$'
safe_for_regex: "{{ '^f.*o(.*)$' | regex_escape() }}"

Return Value

Key

Description

Return value

string

Escaped string.

Returned: success

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.