regexteraterm

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. I originally used the TeraTerm wait command but that has since failed me and I need to make it more robust. 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.

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. 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.


Solution

  • It looks like a teraterm waitregex supports the Oniguruma Regular Expression syntax, https://github.com/kkos/oniguruma/blob/master/doc/RE

    To scan for the Succeeded number use this regex:

    Succeeded: +([0-9]+)
    

    The parenthesis indicate a capture group, e.g. you can reference it with $1

    To scan for the Failed number use this regex:

    Failed: +([0-9]+)
    

    In case you can't use capture groups, you can use positive lookbehinds instead:

    (?<=Succeeded: +)[0-9]+
    

    and

    (?<=Failed: +)[0-9]+