regex_replace

18 views
Skip to first unread message

fusillator

unread,
Apr 12, 2019, 11:00:29 AM4/12/19
to Ansible Project
hi all I don't get why the following regexp replacement matches

vars:
    monit_pkgname: "prefixmonit-5.25.3-1"
   
tasks:

- name: debug
    debug:
      msg: "{{ monit_pkgname_release }}"
    vars:
      monit_pkgname_release: "{{ (monit_pkgname|regex_replace('(?<!prefix)monit-[0-9]+(?:\\.[0-9]+)*-([0-9]+)', '\\1')).split('.') }}"


TASK [debug] ******************************************************************************************************************************************************************
ok: [capsule] => {
    "msg": "[u'finecomonit-5', u'25', u'3-1']"
}

from regexp manual

(?<!...)
Matches if the current position in the string is not preceded by a match for .... This is called a negative lookbehind assertion.

The same happens with caret

vars:
  monit_pkgname_version: "{{ (monit_pkgname|regex_replace('^monit-([0-9]+(?:\\.[0-9]+)*)-[0-9]+', '\\1')).split('.') }}"

The aim would be made the replacement not happen if there's a prefix in monit_pkgname-
any idea?

fusillator

unread,
Apr 12, 2019, 11:21:28 AM4/12/19
to Ansible Project
Solved

 monit_pkgname_version: "{{ (monit_pkgname|regex_replace('monit-([0-9]+(?:\\.[0-9]+)*)-[0-9]+', '\\1')).split('.') if monit_pkgname|regex_search('^monit-') else None }}"
 monit_pkgname_release: "{{ (monit_pkgname|regex_replace('monit-[0-9]+(?:\\.[0-9]+)*-([0-9]+)', '\\1')).split('.') if monit_pkgname|regex_search('^monit-') else None }}"

Raghavendra Rao

unread,
Apr 12, 2019, 11:30:04 AM4/12/19
to ansible...@googlegroups.com
ok

--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/da9e04d0-7e4e-4f12-8463-f447e020c3a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages