I just found a nice way of supplying re.sub compile flags to regex_replace.

https://docs.python.org/2/library/re.html, at '(?iLmsux)'


So for instance, this would not work:

regex_replace('.*([a-z0-9]{40}).*', '\\1')

I just found out that I would need the re.S flag (make '.' match any char).

You can supply that as part of the regex:

regex_replace('(?s).*([a-z0-9]{40}).*', '\\1')


I would preferred this over hard coded flag options in Ansible.


Dick


On 5 January 2017 at 12:12, Dick Visser <[email protected]> wrote:
> Hi
>
> One of my plays tries to do a regex_replace on the returned content of
> the uri module, which is HTML with new lines in it.
> This seems to fail as from the debug output I can see that
> regex_replace doesn't do multiline matching.
>
> I see that there is basically only one flag for re.sub in regex_replace:
>
> https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/filter/core.py#L137-L140
>
> For my regex to work, I would need both the re.MULTILINE and re.DOTALL
> flags to be set for re.sub.
>
> Instead of hard coding one or two flags as arguments, wouldn't it make
> sense to have the filter accept an argument of the raw flags?
>
> This would make things much more flexible (and powerful!).
>
>
>
> --
> Dick Visser
> Sr. System & Network Engineer
> GÉANT
>
> Want to join us? We're hiring: https://www.geant.org/jobs



-- 
Dick Visser
Sr. System & Network Engineer
GÉANT

Want to join us? We're hiring: http://www.geant.org/jobs

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAEQQDN%3Dq9e2F%3DyBpVKAiUbd_5Tm0EoFeg%2BYBPfV%3D2%2BtrWLPy3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to