summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/filter/regex_replace.yml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/plugins/filter/regex_replace.yml')
-rw-r--r--lib/ansible/plugins/filter/regex_replace.yml12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/ansible/plugins/filter/regex_replace.yml b/lib/ansible/plugins/filter/regex_replace.yml
index 0277b560..8c8d0afe 100644
--- a/lib/ansible/plugins/filter/regex_replace.yml
+++ b/lib/ansible/plugins/filter/regex_replace.yml
@@ -5,7 +5,7 @@ DOCUMENTATION:
description:
- Replace a substring defined by a regular expression with another defined by another regular expression based on the first match.
notes:
- - Maps to Python's C(re.replace).
+ - Maps to Python's C(re.sub).
positional: _input, _regex_match, _regex_replace
options:
_input:
@@ -21,11 +21,11 @@ DOCUMENTATION:
type: int
required: true
multiline:
- description: Search across line endings if C(True), do not if otherwise.
+ description: Search across line endings if V(True), do not if otherwise.
type: bool
default: no
ignorecase:
- description: Force the search to be case insensitive if C(True), case sensitive otherwise.
+ description: Force the search to be case insensitive if V(True), case sensitive otherwise.
type: bool
default: no
@@ -40,6 +40,12 @@ EXAMPLES: |
# piratecomment => '#CAR\n#tar\nfoo\n#bar\n'
piratecomment: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_replace('^(.ar)$', '#\\1', multiline=True, ignorecase=True) }}"
+ # Using inline regex flags instead of passing options to filter
+ # See https://docs.python.org/3/library/re.html for more information
+ # on inline regex flags
+ # piratecomment => '#CAR\n#tar\nfoo\n#bar\n'
+ piratecomment: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_replace('(?im)^(.ar)$', '#\\1') }}"
+
RETURN:
_value:
description: String with substitution (or original if no match).