mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Slight tweak to regex examples.
This commit is contained in:
parent
dc4f198bad
commit
9a70dd1c94
1 changed files with 4 additions and 2 deletions
|
@ -304,12 +304,14 @@ To match strings against a regex, use the "match" or "search" filter::
|
||||||
url: "http://example.com/users/foo/resources/bar"
|
url: "http://example.com/users/foo/resources/bar"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- debug: 'msg="Resource URI: {{ url }}"'
|
- shell: "msg='matched pattern 1'"
|
||||||
when: url | match("http://example.com/users/.*/resources/.*")
|
when: url | match("http://example.com/users/.*/resources/.*")
|
||||||
|
|
||||||
- debug: 'msg="Resource path: {{ url }}"'
|
- debug: "msg='matched pattern 2'"
|
||||||
when: url | search("/users/.*/resources/.*")
|
when: url | search("/users/.*/resources/.*")
|
||||||
|
|
||||||
|
'match' will require a complete match in the string, while 'search' will require a match inside of the string.
|
||||||
|
|
||||||
To replace text in a string with regex, use the "regex_replace" filter::
|
To replace text in a string with regex, use the "regex_replace" filter::
|
||||||
|
|
||||||
# convert "ansible" to "able"
|
# convert "ansible" to "able"
|
||||||
|
|
Loading…
Reference in a new issue