From c0b7fcd304beba636e90e4bf3397487ff9772ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gross?= Date: Sun, 26 Jul 2015 19:08:34 +0200 Subject: [PATCH] Add documentation for regex_escape filter --- docsite/rst/playbooks_filters.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docsite/rst/playbooks_filters.rst b/docsite/rst/playbooks_filters.rst index 2f9e83c288f..d95f617f192 100644 --- a/docsite/rst/playbooks_filters.rst +++ b/docsite/rst/playbooks_filters.rst @@ -401,6 +401,11 @@ To replace text in a string with regex, use the "regex_replace" filter:: .. note:: If "regex_replace" filter is used with variables inside YAML arguments (as opposed to simpler 'key=value' arguments), then you need to escape backreferences (e.g. ``\\1``) with 4 backslashes (``\\\\``) instead of 2 (``\\``). +To escape special characters within a regex, use the "regex_escape" filter:: + + # convert '^f.*o(.*)$' to '\^f\.\*o\(\.\*\)\$' + {{ '^f.*o(.*)$' | regex_escape() }} + A few useful filters are typically added with each new Ansible release. The development documentation shows how to extend Ansible filters by writing your own as plugins, though in general, we encourage new ones to be added to core so everyone can make use of them.