0

I am trying to manipulate a string in Ansible with regex_replace. Unfortunately I am not able to get the requested result.

Input string: home0home Output string: home1home

Code:

  - name: String manipulator
    set_fact:
     string: "{{ string| regex_replace('^(.{4}).(.*)$','\\1 1\\2') }}"
  - name:
    debug: msg="{{ string }}"

Output:

ok: [localhost] => {
    "msg": "home 1home"
}

How to get rid of the empty space? If I remove the space in regex, it fails.

0 Answers0