Update playbooks_tests.rst (#76047)

pull/76184/head
Paul 4 years ago committed by GitHub
parent 2955ff57a7
commit e84d660140
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -51,19 +51,19 @@ To match strings against a substring or a regular expression, use the ``match``,
tasks: tasks:
- debug: - debug:
msg: "matched pattern 1" msg: "matched pattern 1"
when: url is match("https://example.com/users/.*/resources/") when: url is match("https://example.com/users/.*/resources")
- debug: - debug:
msg: "matched pattern 2" msg: "matched pattern 2"
when: url is search("/users/.*/resources/.*") when: url is search("users/.*/resources/.*")
- debug: - debug:
msg: "matched pattern 3" msg: "matched pattern 3"
when: url is search("/users/") when: url is search("users")
- debug: - debug:
msg: "matched pattern 4" msg: "matched pattern 4"
when: url is regex("example.com/\w+/foo") when: url is regex("example\.com/\w+/foo")
``match`` succeeds if it finds the pattern at the beginning of the string, while ``search`` succeeds if it finds the pattern anywhere within string. By default, ``regex`` works like ``search``, but ``regex`` can be configured to perform other tests as well, by passing the ``match_type`` keyword argument. In particular, ``match_type`` determines the ``re`` method that gets used to perform the search. The full list can be found in the relevant Python documentation `here <https://docs.python.org/3/library/re.html#regular-expression-objects>`_. ``match`` succeeds if it finds the pattern at the beginning of the string, while ``search`` succeeds if it finds the pattern anywhere within string. By default, ``regex`` works like ``search``, but ``regex`` can be configured to perform other tests as well, by passing the ``match_type`` keyword argument. In particular, ``match_type`` determines the ``re`` method that gets used to perform the search. The full list can be found in the relevant Python documentation `here <https://docs.python.org/3/library/re.html#regular-expression-objects>`_.

Loading…
Cancel
Save