ansible.builtin.regex_search filter – extract regex match from string
Note
This filter plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
regex_search
even without specifying the collections:
keyword.
However, we recommend you use the FQCN for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
New in Ansible 2.0
Synopsis
Search in a string to extract the part that matches the regular expression.
Input
This describes the input of the filter, the value before | ansible.builtin.regex_search
.
Parameter |
Comments |
---|---|
String to match against. |
Positional parameters
This describes positional parameters of the filter. These are the values positional1
, positional2
and so on in the following example: input | ansible.builtin.regex_search(positional1, positional2, ...)
.
Parameter |
Comments |
---|---|
Regular expression string that defines the match. |
Keyword parameters
This describes keyword parameters of the filter. These are the values key1=value1
, key2=value2
and so on in the following example: input | ansible.builtin.regex_search(key1=value1, key2=value2, ...)
.
Parameter |
Comments |
---|---|
Force the search to be case insensitive if Choices:
|
|
Search across line endings if Choices:
|
Notes
Note
Maps to Python’s
re.search
.
Examples
# db => 'database42'
db: "{{ 'server1/database42' | regex_search('database[0-9]+') }}"
# drinkat => 'BAR'
drinkat: "{{ 'foo\nBAR' | regex_search('^bar', multiline=True, ignorecase=True) }}"
Return Value
Key |
Description |
---|---|
Matched string or empty string if no match. Returned: success |
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.