How to specify a regular expression in a property checkpoint in a keyword test
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to specify a regular expression in a property checkpoint in a keyword test
I need to check the following text displayed in a textbox.
08/30/2016 16:31:48 - Attempting to connect to DMM.
I need to express the date/time stamp in a regular expression so that it accounts for the new date/time stamp (i.e., if the test is run tomorrow).
I am having issues with the syntax. As of now, this is what I have but not working. Again, I need to express this in a keyword test.
\d\d/\d\d/\d\d/\d\d \d\d:\d\d:\d\d - Attempting to connect to DMM.
Any help will be much appreciated.
Miguel
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
https://support.smartbear.com/viewarticle/81060/
Look at the table for the section regarding backslash. I think that will help you.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your reply.
I looked at that table initially and that is how I came up with the posted expression; however, something is wrong obviously. I was in the hopes that someone here could identify the issue with it. Again, thank you for any light someone can shed on it.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
your regex not not working since
1)you have broken YYYY in to two(like this 08/30/20/1616:31:48)
2) haven't specify the space between year and hours pat of time
try following ....haven't tested but hope no syntax errors........
\d\d/\d\d/\d\d\d\d\s\d\d:\d\d:\d\d( - Attempting to connect to DMM.)
ps. not sure : is a special character or not if so hav to use \:
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This regex will match your string:
(\d{2}\/\d{2}\/\d{4}) (\d{2}:\d{2}:\d{2}) - (Attempting to connect to DMM\.)
Please remember that / delimiter (as well as another delimiters) always should be escaped by backslash \
Also it is better to escape the dot character: \. Otherwise it will match any character.
And if you group different logical members of your string inside parentheses, it makes your regex more readable.
Great online tool to check your regex: https://regex101.com/
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@baxatob I used the online tool you recommended and the expression was validated successfully. The problem though is when I plug it into TestComplete for some reason does not like it. I tried to escape the ':' and ''' (single quote) as well for the string under test but no success.
Using the online tool...
This expression:
(\d{2}\/\d{2}\/\d{4})\s(\d{2}\:\d{2}\:\d{2})\s-\s(Attempting to connect to DMM\.)
(\d{2}\/\d{2}\/\d{4})\s(\d{2}\:\d{2}\:\d{2})\s-\s(Attempting to connect to a DMM on port \'COM1\')
(\d{2}\/\d{2}\/\d{4})\s(\d{2}\:\d{2}\:\d{2})\s-\s(Unable to connect to DMM\.)
Matches the following:
09/09/2016 11:25:31 - Attempting to connect to DMM.
09/09/2016 11:25:31 - Attempting to connect to a DMM on port 'COM1'
09/09/2016 11:25:32 - Unable to connect to DMM.
Not sure what else to do.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@mcastellanos, can you show how did you use the regular expression within TestComplete framework?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The below is when defining/updating the checkpointThis is the result that errors out.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hm... Only thing I can advise is to check carefully spaces between records of your log, and how it matches your pattern.
Use \s token everywhere instead of literal spaces.
