Forum Discussion
mcastellanos, can you show how did you use the regular expression within TestComplete framework?
The below is when defining/updating the checkpoint
- baxatob8 years agoCommunity Hero
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.
- joseph_michaud8 years agoModerator
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\.)