简体   繁体   English

寻找匹配特定单词和数字范围的正则表达式

[英]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.

相关问题 与特定数字组匹配的确切长度的正则表达式 - Regex of exact length that matches specific group of numbers Javascript RegEx将所有单词提取为单个匹配项,但不从字符串中提取数字 - Javascript RegEx extract all words as single matches but not numbers from a string Javascript正则表达式匹配模式,用于将单词和数字与空格和逗号匹配 - Javascript Regex Match pattern that matches words and numbers with spaces and commas 正则表达式返回一个范围的匹配,并包含Ruby中的几个单词之一 - regex that returns matches of a range in length and containing one of several words in Ruby 正则表达式用于特定范围内的逗号分隔数字 - Regex for comma separated numbers within specific range 如何创建匹配两个或更多特定整个单词的正则表达式? - How to create a regex that matches two or more specific whole words? 匹配两个或三个单词的正则表达式,但如果它是特定单词则不捕获第三个 - Regex that matches two or three words, but does no catpure the third if it is a specific word 正则表达式:替换除数字、特定字符和特定单词之外的所有内容 - Regex: Replace all except numbers, specific characters and specific words 寻找正则表达式模式以获取最大匹配 - Looking for Regex pattern for maximum matches 如何使用sed仅替换特定范围的正则表达式匹配? - How do I replace only a specific range of regex matches with sed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM