regex_replace flags

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!).

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