On Wednesday, 14 February 2018 16.36.33 CET 'Felix Fontein' via Ansible Project 
wrote:
> > The task seems obvious at first glance but it appears to be difficult
> > to implement in this context.
> > The string is:
> > host_meta: "<XRD
> > xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n <Link
> > rel='restconf' href='/restconf'/>\n</XRD>"
> > 
> > I need to extract the values of rel and href into api_release and
> > api_root. I unsuccessfully tried the following:
> > - set_fact: api_release="{{ host_meta | regex_replace('^.*
> > rel=(.*) .*$', '\\1') }}"
> >   when: host_meta is defined
> > 
> > - set_fact: api_root="{{ host_meta | regex_replace('^.*
> > href=(.*)/>.*$', '\\1') }}"
> >   when: host_meta is defined
> 
> You are missing the newlines the string contains. regex_replace uses
> re.sub() in Python and does not offer a way to set the MULTILINE flag.
> If you remove '^' and '$' from your regexps, you can see what happens:
> only the matching part between two '\n's is replaced.


It's possible to turn on multiline, but the dot doesn't match newline so DOTALL 
flag need to be set to.

This can be done with (?mS), "m" is multiline and "S" is DOTALL.

So this should work:

- set_fact:
    api_release: "{{ host_meta | regex_replace('(?ms)^.* rel=(.*) .*$', '\\1') 
}}"


-- 
Kai Stian Olstad

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3038237.GlpWJfDGSG%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply via email to