Slight tweak to regex examples.

This commit is contained in:
Michael DeHaan 2014-04-29 16:53:52 -04:00
parent dc4f198bad
commit 9a70dd1c94

View file

@ -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"