Ansible Filter regex replace: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=External= * https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#searching-strings-with-regular-expressions =Internal= * Ansible Filters#regex_replace|...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
* [[Ansible Filters#regex_replace|Ansible Filters]] | * [[Ansible Filters#regex_replace|Ansible Filters]] | ||
=Overview= | =Overview= | ||
=Apply the Regular Expression to Each Element of a List= | |||
The pipeline produces a list that is then processed with <code>regex_replace</code>. | |||
<syntaxhighlight lang='text'> | |||
... | map('regex_replace', '<matching-regex>', '<replacement-expression>') | list | |||
</syntaxhighlight> | |||
<syntaxhighlight lang='text'> | |||
"{{ java_modules_result.files | json_query('[*].path') | map('regex_replace', '(.*/Contents/Home)/jmods/(.*)\\.jmod', 'jrt://\\1!/\\2') | list }}" | |||
</syntaxhighlight> |
Latest revision as of 09:18, 5 July 2021
External
Internal
Overview
Apply the Regular Expression to Each Element of a List
The pipeline produces a list that is then processed with regex_replace
.
... | map('regex_replace', '<matching-regex>', '<replacement-expression>') | list
"{{ java_modules_result.files | json_query('[*].path') | map('regex_replace', '(.*/Contents/Home)/jmods/(.*)\\.jmod', 'jrt://\\1!/\\2') | list }}"