From c1e4085251ddfd4e126b761120183d4054f1cb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gross?= Date: Wed, 6 Aug 2014 10:56:16 +0200 Subject: [PATCH] Add regular expression escaping filter. --- lib/ansible/plugins/filter/core.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index e8e3e17f775..a4f16e907d4 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -222,6 +222,10 @@ def version_compare(value, version, operator='eq', strict=False): except Exception, e: raise errors.AnsibleFilterError('Version comparison: %s' % e) +def re_escape(string): + '''Escape all regular expressions special characters from STRING.''' + return re.escape(string) + @environmentfilter def rand(environment, end, start=None, step=None): r = SystemRandom() @@ -356,6 +360,7 @@ class FilterModule(object): 'search': search, 'regex': regex, 'regex_replace': regex_replace, + 're_escape': re_escape, # ? : ; 'ternary': ternary,