Forum Discussion

jmarkman's avatar
jmarkman
Occasional Contributor
6 years ago

FindAllChildren regex difficulties

I'm trying to capture several different forms of a grid's rows; if a row is enabled or disabled, the class name changes between "trip-details" and "trip-details cancelled". I had the regex pattern to use in conjunction with the FindAllChildren method:

 

trip-details\s*(cancelled)*

However, there's a stipulation that comes with the FindAllChildren method and regex:

Patterns search for partial matches. For example, regexp:notepad matches both "notepad" and "notepad++". To search for an exact match, use the ^ and $ anchors, for example "regexp:^notepad$". 

- Documentation for FindAllChildren

 

How would I go about including the anchors? The regex breaks when I test the additions in a site like Regexr (the regex is available at https://regexr.com/3vah8), but does the anchor placement in TestComplete differ enough from traditional regex in this regard that I can just slap the anchors at the start and end to prevent partial matches?

 

 

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    TestComplete RegEx is different than standard when being used within the FindAllChildren. So, follow the instructions from the TestComplete documentation and you should be good.

    • jmarkman's avatar
      jmarkman
      Occasional Contributor

      Well, after playing around with it for a while, it looks like I'm not good. I tried

       

      var rows = myElement.FindAllChildren("className", "regexp:^trip-details\s*(cancelled)*$", 5).toArray();

      and this seems to only return anything containing trip-details instead of that AND trip-details cancelled if it is present.