blob: 0277b5605ea349ada9ecdee99c805ab898951f27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
|