[英]Looking for REGEX that matches specific words and range of numbers
I am working on a TeraTerm script that will is waiting for one of 2 possible results.我正在研究一个 TeraTerm 脚本,它将等待两个可能的结果之一。 I originally used the TeraTerm wait command but that has since failed me and I need to make it more robust.我最初使用的是 TeraTerm 等待命令,但后来我失败了,我需要让它更健壮。 Here is an example of the results I am parsing against:这是我正在解析的结果的示例:
Summary for local
------------
Succeeded: 2 (changed=1)
Failed: 0
Passing would be "Succeeded" with any number greater than 0. Likewise, failing would be "Failed" with any number greater than 0.任何大于 0 的数字都表示“成功”。同样,任何大于 0 的数字都表示“失败”。
I have yet to really grasp regex and the generator / testing sites don't help with my lack of understanding (and lack of time to invest).我还没有真正掌握正则表达式,并且生成器/测试站点对我缺乏理解(以及缺乏投资时间)没有帮助。
I get that something like [A-Za-z] and [1-9] might be of use but testing them, I am not sure how to go beyond every character returned or just a single character.我知道 [A-Za-z] 和 [1-9] 之类的东西可能有用,但在测试它们时,我不确定如何在返回的每个字符或单个字符之外进行 go。 In the case above, the words are constant, the digit is not.在上述情况下,单词是恒定的,数字不是。 I am not sure if the whitespace between the word and number are spaces or tabs.我不确定单词和数字之间的空格是空格还是制表符。
It looks like a teraterm waitregex
supports the Oniguruma Regular Expression syntax, https://github.com/kkos/oniguruma/blob/master/doc/RE看起来 teraterm waitregex
支持 Oniguruma 正则表达式语法https://github.com/kkos/oniguruma/blob/master/doc/RE
To scan for the Succeeded
number use this regex:要扫描Succeeded
的号码,请使用此正则表达式:
Succeeded: +([0-9]+)
The parenthesis indicate a capture group, eg you can reference it with $1
括号表示一个捕获组,例如您可以使用$1
引用它
To scan for the Failed
number use this regex:要扫描Failed
号码,请使用此正则表达式:
Failed: +([0-9]+)
In case you can't use capture groups, you can use positive lookbehinds instead:如果你不能使用捕获组,你可以使用积极的后向观察来代替:
(?<=Succeeded: +)[0-9]+
and和
(?<=Failed: +)[0-9]+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.