gpt4 book ai didi

regex - Ansible regex_replace-ho 提取特定值

转载 作者:行者123 更新时间:2023-12-04 02:26:24 26 4
gpt4 key购买 nike

我如何使用 regex_replace 像这样从主机名中提取此值。

我有 regex_replace

"{{ inventory_hostname | regex_replace('^\\D+|\\..*', '') }}"

像这样的主机名

nginx09-2.domain.com

我只想在 - (2) 之后提取数字,但我的 regex_replace 提取 09-2。

最佳答案

您可以捕获数字并用它替换字符串:

"{{ inventory_hostname | regex_replace('^.*-(\\d+).*$', '\\1') }}"

- debug:
msg: "{{ 'nginx09-2.domain.com' | regex_replace('^.*-(\\d+).*$', '\\1') }}"

# 2

关于regex - Ansible regex_replace-ho 提取特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67298153/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com