regex - 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"
}
如何摆脱空白?如果我删除正则表达式中的空格,它会失败。
解决方案
推荐阅读
- html - 根据该图像坐标将图像放在 VueJS/Vuetify 中的另一个上
- php - 将 id 值提交到购物车页面 php
- c++ - 通过它的模板类重载 C++ 模板类方法
- node.js - Electron - 未捕获的错误:EROFS:只读文件系统
- c# - 我怎样才能钳制旋转?
- ios - 在 Swift / SwiftUI 中一次更新列表中的每个按钮项,而不是一次更新所有按钮
- robotframework - 在 Robot Framework 中使用 For 循环进行分页
- python - Not recognizing commands in discord with Python
- javascript - 为什么Proxy无法捕捉箭头函数中的集合
- python - 正则表达式提取 URL 而不需要不需要的单词