Forum Discussion

TestQA1's avatar
TestQA1
Frequent Contributor
6 months ago
Solved

Regex to verify a string

Hi,

I have a below function. The regEx is intended to match the string for example: "2023-09-07 11:20:15 error description" and it uses '.' to include some text between time and error description. But, I don't know how to use variables in regEx like DateTime[0] and DateTime[1] have been used here. When I run this script it throws regEx using invalid flags. 

Please note the text area has multiline entries.

I also wanted to know if getText() and wText() supports any indexing to get a string at particular index or line. That would be an easier alternative than using regEx.

 

function TestErrorExample(error) {
var DateTime = CurrDateTime();
var date = DateTime[0];
var time = DateTime[2];
var regEx = "/DateTime[0].DateTime[2].+(error)";
var findE;
textArea = textArea();
text = textArea.getText();
if (
findE = new RegExp(regEx, text)
) {
Log.Checkpoint(
"Passed");
} else {
Log.Error("Failed");
}
}

 

Thanks.

5 Replies