Skip to content

regex_findall

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 2.0.

Synopsis

  • Search in a string or extract all the parts of a string matching a regular expression.

Parameters

Parameter Defaults / Choices Comments
_input
str
required
String to match against.
_regex
str
Regular expression string that defines the match.
ignorecase
bool
Force the search to be case insensitive if V(True), case sensitive otherwise.
multiline
bool
Search across line endings if V(True), do not if otherwise.

Examples

# all_pirates => ['CAR', 'tar', 'bar']
all_pirates: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_findall('^.ar$', 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
# all_pirates => ['CAR', 'tar', 'bar']
all_pirates: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_findall('(?im)^.ar$') }}"

# get_ips => ['8.8.8.8', '8.8.4.4']
get_ips: "{{ 'Some DNS servers are 8.8.8.8 and 8.8.4.4' | regex_findall('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}"

Return Values

Key Data Type Description Returned
_value list List of matched strings.