Forum Discussion

Rafael_Fradczyk's avatar
Rafael_Fradczyk
Occasional Contributor
9 years ago

regular expressions in property checkpoint

Hi everybody,

 

I have an issue with regular expression in property checkpoints.

I want to compare a string. In this string there's the current daytime. So to compare this string I need to substitute the daytime with a regular expression. Here's my string:

 

18:23:45 - test123

 

This is my regular expression to compare the string:

 

\d\d:\d\d:\d\d - test123

 

So, this works just fine! My problem is, when I try to compare a string with two or more lines, like this:

 

18:23:45 - test123

18:23:52 - test456

 

 

This expression won't work in TestComplete:

 

\d\d:\d\d:\d\d - test123

\d\d:\d\d:\d\d - test456

 

I just don't know why this won't work. any ideas?

Thanks!

 

  • The first option is try '\d\d:\d\d:\d\d - test123[\s]*\d\d:\d\d:\d\d - test456'. The \s matches the newline character. This works where there is full support for regular expressions. 

     

    If that does not work, try this '\d\d:\d\d:\d\d - test123[\b\n]*\d\d:\d\d:\d\d - test456' (As per this article)

     

    Last option, you can move the checkpoint to use scripting and let VBScript handle the checking.

     

    E.G.

    FUNCTION lib_isRegexMatch(ByVal strPattern, ByVal SearchInThisStr)
    DIM re : SET re = NEW RegExp
    WITH re
    .Pattern = strPattern
    .Global = FALSE
    .IgnoreCase = TRUE
    END WITH
    lib_isRegexMatch = re.Test(SearchInThisStr)
    END FUNCTION

    You can change the global and ignorecase flags as required.

  • djadhav's avatar
    djadhav
    Regular Contributor

    The first option is try '\d\d:\d\d:\d\d - test123[\s]*\d\d:\d\d:\d\d - test456'. The \s matches the newline character. This works where there is full support for regular expressions. 

     

    If that does not work, try this '\d\d:\d\d:\d\d - test123[\b\n]*\d\d:\d\d:\d\d - test456' (As per this article)

     

    Last option, you can move the checkpoint to use scripting and let VBScript handle the checking.

     

    E.G.

    FUNCTION lib_isRegexMatch(ByVal strPattern, ByVal SearchInThisStr)
    DIM re : SET re = NEW RegExp
    WITH re
    .Pattern = strPattern
    .Global = FALSE
    .IgnoreCase = TRUE
    END WITH
    lib_isRegexMatch = re.Test(SearchInThisStr)
    END FUNCTION

    You can change the global and ignorecase flags as required.