【发布时间】:2018-05-21 13:17:55
【问题描述】:
我正在尝试使用 Ansible 中的 replace 模块,但我不知道如何使用 regexp 匹配某些字符串。
我正在尝试匹配以字符 $ 开头的字符串,但 ansible 一直说他是 found unknown escape character '$'。
我知道 ansible 使用与 python 相同的正则表达式规则,但我在 python 中也不能这样做,你们知道怎么做吗?
我已经尝试过这些正则表达式规则:
^\$、[!^$]、[!^$] 和 \s*[!^$]
最后 3 条规则匹配以 $ 开头的字符串,但如果字符串不以 $ 开头,则也匹配那些字符串。
最后 3 条规则的一些示例:
foo doesn't match
$foo match
$$$$ match
foo$ match
foo$bar match
我只需要在这种情况下匹配:
foo
$foo this case
$$$$ this case
foo$
foo$bar
【问题讨论】:
-
这应该适用于您的情况:'^\$.*$'
标签: python regex python-2.7 replace ansible