【问题标题】:regex to capture text from multiple lines in Ansible正则表达式从 Ansible 中的多行捕获文本
【发布时间】:2019-10-09 17:33:03
【问题描述】:

从下面的文本中,我想捕获从“this”开始的文本,直到找到第一个“!” (东海岸前的那个)

我正在使用正则表达式 /^this.*>!/ 如果下面显示的文本是标准输出格式,它可以工作..但它在标准输出行时不起作用。我在 ansible 上使用 regex_search 来解决这个问题

this device version

  1.2.3 network systems

  new york rhode island

  new england Connecticut

!

east coast cities

!

【问题讨论】:

  • Ansible 支持 multilineregex_search,例如{{ 'foo\nBAR' | regex_search("^bar", multiline=True, ignorecase=True) }}。见Filters

标签: regex ansible


【解决方案1】:

不知道 ansible 但阅读您想要实现的目标,我建议您使用:

/^this[^!]*/s

^this 在开头查找字符串“this”

[^!]* 查找零个或多个不是“!”的字符

/s 允许您搜索多行

【讨论】:

  • 谢谢。看起来 Ansible 中的 regex_search 函数只能 grep 一行。需要找到一种方法来迭代每一行的正则表达式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-12
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多