-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regex: groupdict: return dict of named capture groups #64474
Conversation
could you add tests and a changelog entry as a 'minor_change' as it would be a good feature to record? |
5a57726
to
6a2bfce
Compare
6a2bfce
to
153167b
Compare
@bcoca I've added the tests and changelog as you requested. Would be nice to have this in for 2.10. |
@@ -1396,12 +1396,23 @@ To search a string with a regex, use the "regex_search" filter:: | |||
# case insensitive search in multiline mode | |||
{{ 'foo\nBAR' | regex_search("^bar", multiline=True, ignorecase=True) }} | |||
|
|||
.. versionadded:: 2.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamescassell Could you please change the version and rebase this PR? Thanks.
Hi! Thank you very much for your submission to Ansible. It means a lot to us that you've taken the time to contribute. But we do not want to overload the existing filter and think a new filter might be better fit for purpose. However, we recommend looking into providing this functionality through Ansible Galaxy via Ansible Collections. You can find more information about collections at: Because this project is very active, we're unlikely to see comments made on closed tickets and we lock them after some time. See this page for a complete and up to date list of communication channels and their purposes: Thank you once again for this and your interest in Ansible! |
SUMMARY
Return named capture groups as a dict from the regex_search and regex_findall filters.
This makes ugly list comprehensions much simpler by allowing it to be boiled to a single regex_findall.
(an example of a complicated case: https://github.com/MindPointGroup/RHEL7-STIG/blob/d0b128cef334374257a7f85d1fcb25b0653f64e0/tasks/parse_etc_passwd.yml#L10-L28 )
ISSUE TYPE
COMPONENT NAME
regex_search
regex_findall
ADDITIONAL INFORMATION