Forum Discussion

baxatob's avatar
baxatob
Community Hero
9 years ago

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...
  • HKosova's avatar
    9 years ago

    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" anywhere

     

    You 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();