Skip to content

regex_escape

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 2.8.

Synopsis

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

Parameters

Parameter Defaults / Choices Comments
_input
str
required
String to escape.
re_type
str
Default: python
Choices: python, posix_basic
Which type of escaping to use.

Notes

Note

  • posix_extended is not implemented yet

Examples

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

Return Values

Key Data Type Description Returned
_value str Escaped string.