【发布时间】:2022-12-07 22:50:41
【问题描述】:
我目前正在使用 regex101 来尝试计算以下内容,我希望能够捕获完整的项目数据,例如 name_template_2 及其相关描述,定义和写入数据
这是我的数据模型
templates:
name_template:
description: test_description
define: yes
write: true
name_template_2:
description: test_description2
define: false
write: true
我可以通过以下方式捕获我需要的行
^[[:space:]][[:space:]][[:space:]][[:space:]].*
和
^[[:space:]][[:space:]]name_template_2:
但我无法将这两种模式结合在一起以仅过滤与 name_template_2 相关的键和数据。我在网上看的越多,我就越了解它。有没有人以前实现过这个或者有更有效的方法来做到这一点?
【问题讨论】:
-
什么是工具或语言?
-
正在使用ansible
-
也许像这样有 2 个捕获组?
^[^\S\n]{2}(name_template_2:)((?:\n[^\S\n]{4}\S.*)+)regex101.com/r/jbnGpw/1 -
哇,非常感谢你,我会看看捕获组并尝试锻炼腰部。
标签: regex dictionary yaml