Forum Discussion

Sravani93's avatar
Sravani93
Occasional Contributor
3 years ago

Compare a value returned dynamically using regEx

Hi  I want to compare a text returned by an object using regEx as the number in actual text changes dynamically.   Here is what I am using      var actualName = "Test_QA (Abcdef XY8)";      var ...
  • rraghvani's avatar
    3 years ago

    Note: the regular expression syntax adopted in TestComplete may differ from native regular expression syntax provided by scripting engines

     

     

    function Test4()
    {
        var str = "Test_QA Abcdef XY1";
        var pattern1 = /Test_QA Abcdef XY\d{1,3}/gm // native regular expression will match 0 - 999
        var pattern2 = new RegExp("Test_QA Abcdef XY\\d{1,3}"); Note \\ is used
    
        Log.Message(pattern1.test(str));
        Log.Message(pattern2.test(str));
        
        aqObject.CompareProperty(str, cmpMatches, "^Test_QA Abcdef XY\\z$", false, lmError); // TC regular expression
    }

     

    See Regular Expressions Syntax