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
Read the help topic that @Marsha_R referenced: Regular Expressions Syntax
Keep in mind that the Property Checkpoint is using the section titled "Tokens Used in Non-Native Regular Expressions"
In it you'll see that we don't support the repetition syntax '{n}'. Also, note that JScript (but not VBScript) will want to have backslashes escaped. So if I were doing a script test for JScript I would use '\\d' for matching a digit. To make this more confusing, if I were doing a keyword test for JScript I would enter '\d' in the wizard. (The wizard will internally escape the backslash. If you look closely at the 'Value' field for the Property Checkpoint operation in an existing JScript keyword test, you'll see evidence of the escaped backslash...)
I find getting regular expressions to work to be quite frustrating. I usually go through a round of trial and error. If given this string
08/30/2016 16:31:48 - Attempting to connect to DMM.
Let's assume JScript. I would first try this regular expression: 08/30/2016.*
That worked. Next try: \\d\\d/30/2016.*
That worked too. How about: \\d{2}/30/2016.*
Nope, that didn't work.
Let's jump ahead. How about: \\d\\d/\\d\\d/\\d\\d\\d\\d\b*\\d\\d:\\d\\d:\\d\\d\b*-\b*Attempting to connect to DMM\.
Dang it! That didn't work (and that's what I get for trying to jump ahead...) What did I do wrong? Oh, I forgot to escape the backslashes for \b:
\\d\\d/\\d\\d/\\d\\d\\d\\d\\b*\\d\\d:\\d\\d:\\d\\d\\b*-\\b*Attempting to connect to DMM\.
OK. That worked. Note that whitespace is matched with \b and not \s.
I like @baxatob idea of grouping. Let's try this
(\\d\\d/\\d\\d/\\d\\d\\d\\d)\\b*(\\d\\d:\\d\\d:\\d\\d)\\b*-\\b*(Attempting to connect to DMM\.)
Good. That worked too.
If you're not using JScript, then the specification would look like this:
(\d\d/\d\d/\d\d\d\d)\b*(\d\d:\d\d:\d\d)\b*-\b*(Attempting to connect to DMM\.)

- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »