From 49c463f98b36dab0aceab1a9a4407304ff99c79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Thu, 2 Oct 2014 19:11:48 +0200 Subject: [PATCH] Added a note about escaping backreferences when using 'regex_replace' filter. Users will often be puzzled why 'regex_replace' is not working as intended when used inside YAML arguments. This note explains what they have to do to get it working. --- docsite/rst/playbooks_variables.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docsite/rst/playbooks_variables.rst b/docsite/rst/playbooks_variables.rst index c5eeff01350..bdb4e3ddef4 100644 --- a/docsite/rst/playbooks_variables.rst +++ b/docsite/rst/playbooks_variables.rst @@ -355,6 +355,9 @@ To replace text in a string with regex, use the "regex_replace" filter:: # convert "foobar" to "bar" {{ 'foobar' | regex_replace('^f.*o(.*)$', '\\1') }} +.. 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 (``\\``). + 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.