regex¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Synopsis¶
- Compare string against regular expression using Python's match, fullmatch or search functions.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input string required |
String to match. | |
| ignorecase boolean |
Use case insensitive matching. | |
| match_type string |
Default: search Choices: match, search, fullmatch |
Decide which function to be used to do the matching. |
| multiline boolean |
Match against multiple lines in string. | |
| pattern string required |
Regex to match against. |
Examples¶
- name: check if string matches regex
assert:
that:
- 'url is regex("example\.com/\w+/foo")'
vars:
url: "https://example.com/users/foo/resources/bar"
- name: check if string matches regex ignoring case
assert:
that:
- 'url is regex("EXAMPLE\.COM/\w+/foo", ignorecase=True)'
vars:
url: "https://Example.com/users/foo/resources/bar"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | boolean | Returns V(True) if there is a match, V(False) otherwise. |
Authors¶
- Ansible Core