正则表达式从Ansible中的多行捕获文本

时间:2019-10-09 17:33:03

标签: regex ansible

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

我正在使用正则表达式/^this.*>!/,如果下面显示的文本为stdout格式,则可以使用。.但是,当它位于stdout_lines中时,则不起作用。我为此使用regex_search

this device version

  1.2.3 network systems

  new york rhode island

  new england Connecticut

!

east coast cities

!

1 个答案:

答案 0 :(得分:0)

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

if(!(i%3))

/^this[^!]*/s在字符串开头查找字符串“ this”

^this查找零个或多个不是'!'的字符

[^!]*允许您搜索多行