Regex to verify a string
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
BDD Tests
-
Desktop Testing
-
Script Tests
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could pick apart the string using these methods and compare them that way.
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/methods.html
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/methods.html
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you trying to use regular expression to extract a pattern from your string "2023-09-07 11:20:15 error description"?
What are you trying to extract?
Or if you could provide a screenshot, and give a description of what you want to test?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For now, I found an alternative and instead of using RegEx I am getting all data into an array and using substring match to find the right values.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@rraghvani You're probably right about that. I once shoved a whole Word doc into a variable in TC and parsed that string for what I wanted. 😁
