Non-native regular expressions
Hi!
I need to find all links contained "Obi Wan" text.
I am trying to use regular expression this way:
app.FindAll(["ObjectType", "contentText"], ["Link", "regexp:\bObi Wan\b"], 10)
and it does not work. I receive an empty array.
At the same time this code:
app.FindAll(["ObjectType", "contentText"], ["Link", "Obi Wan Kenobi"], 10)
works perfectly! But it will return only one kind of Obi Wan
I am confused what I do wrong using "regexp: pattern" expression...?
I face this issue both on TC 11.1 and 11.2
May be somebody is able to check on his side?
First of all, consider using wildcards - they are much easier to work with:
"Obi Wan*" - match strings that start with "Obi Wan"
"*Obi Wan*" - match strings that contain "Obi Wan" anywhereYou only need regular expressions if you want to match whole words. For example, match "Obi Wan", "Obi Wan Kenobi" and "Master Obi Wan", but not "Obi Wanderer" or "Mobi Wan". Note that "regexp:" works only in TestComplete 11.2+.
To match "Obi Wan" at the beginning of the link text, full words only, use:
"regexp:^Obi Wan(\\b.*)?$"To match "Obi Wan" anywhere in the link text, full words only:
"regexp:^(.*\\b)?Obi Wan(\\b.*)?$"\\b here means a whitespace, not a word boundary like in some regexp engines. See here for a list of supported tokens. Note the double \\ - escaping is needed because \b with a single \ is a special character for Backspace.
Also remember you need to convert the returned array to the JScript array format:
var arr = app.FindAll(...); arr = (new VBArray(arr)).toArray();