diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /lib/ansible/plugins/filter/regex_replace.yml | |
parent | Initial commit. (diff) | |
download | ansible-core-upstream.tar.xz ansible-core-upstream.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ansible/plugins/filter/regex_replace.yml')
-rw-r--r-- | lib/ansible/plugins/filter/regex_replace.yml | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/ansible/plugins/filter/regex_replace.yml b/lib/ansible/plugins/filter/regex_replace.yml new file mode 100644 index 0000000..0277b56 --- /dev/null +++ b/lib/ansible/plugins/filter/regex_replace.yml @@ -0,0 +1,46 @@ +DOCUMENTATION: + name: regex_replace + version_added: "2.0" + short_description: replace a string via regex + 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). + positional: _input, _regex_match, _regex_replace + options: + _input: + description: String to match against. + type: str + required: true + _regex_match: + description: Regular expression string that defines the match. + type: int + required: true + _regex_replace: + description: Regular expression string that defines the replacement. + type: int + required: true + multiline: + description: Search across line endings if C(True), do not if otherwise. + type: bool + default: no + ignorecase: + description: Force the search to be case insensitive if C(True), case sensitive otherwise. + type: bool + default: no + +EXAMPLES: | + + # whatami => 'able' + whatami: "{{ 'ansible' | regex_replace('^a.*i(.*)$', 'a\\1') }}" + + # commalocal => 'localhost, 80' + commalocal: "{{ 'localhost:80' | regex_replace('^(?P<host>.+):(?P<port>\\d+)$', '\\g<host>, \\g<port>') }}" + + # piratecomment => '#CAR\n#tar\nfoo\n#bar\n' + piratecomment: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_replace('^(.ar)$', '#\\1', multiline=True, ignorecase=True) }}" + +RETURN: + _value: + description: String with substitution (or original if no match). + type: str |