首页 > 解决方案 > Ansible 正则表达式转义字符

问题描述

我正在尝试使用 regex_replace 在 Ansible 中操作字符串。不幸的是,我无法获得要求的结果。

输入字符串:home0home 输出字符串:home1home

代码:

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

输出:

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

如何摆脱空白?如果我删除正则表达式中的空格,它会失败。

标签: regexstringansiblecharacter

解决方案


推荐阅读