Sravani93
3 years agoOccasional Contributor
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 regExPattern = "Test_QA \(Abcdef XY\d{1,2}\)";
aqObject.CompareProperty(actualName, cmpMatches, regExPattern);
Output: The property value "Test_QA (Abcdef XY8)" does not match the pattern "Test_QA (Abcdef XYd{1,2})". 20:02:51 Normal 0.00
Can you please help with the right syntax?
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 }