blob: 970de621954f2e33c0939cf4b4cea6ca32e71a35 (
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
|
DOCUMENTATION:
name: regex_search
version_added: "2.0"
short_description: extract regex match from string
description:
- Search in a string to extract the part that matches the regular expression.
notes:
- Maps to Python's C(re.search).
positional: _input, _regex
options:
_input:
description: String to match against.
type: str
required: true
_regex:
description: Regular expression string that defines the match.
type: str
multiline:
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 V(True), case sensitive otherwise.
type: bool
default: no
EXAMPLES: |
# db => 'database42'
db: "{{ 'server1/database42' | regex_search('database[0-9]+') }}"
# 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
# server => 'sErver1'
db: "{{ 'sErver1/database42' | regex_search('(?i)server([0-9]+)') }}"
# drinkat => 'BAR'
drinkat: "{{ 'foo\nBAR' | regex_search('^bar', multiline=True, ignorecase=True) }}"
RETURN:
_value:
description: Matched string or empty string if no match.
type: str
|