cancel
Showing results for 
Search instead for 
Did you mean: 

Use .Find to get all elements that do NOT match the search properties

SOLVED
Highlighted
Community Leader

Use .Find to get all elements that do NOT match the search properties

Hi all,

 

I'm trying to find a way to make my code less loopy and possibly improve the performance.  I'm trying to take a list of items, get rid of the items that I'm not interested in, and keep the rest

 

Example items*:

Red Tomato

Orange Carrot

Red Strawberry

Green Lettuce

Red Cherry

...

 

I wan't to find all the fruit/veg that aren't red.  I don't know how many fruit or vegetables there are that aren't red - this can vary - but I expect that the majority of the fruit/veg will be red.  I can't go through all the colours that aren't red and find them one by one and add them, because I don't know which colours of fruit/veg there will be.  I could find ALL the fruit/veg then loop through those objects and remove everything that's red - which is what I generally do now - but it seems a waste to return such a large amount of items if all I need to do is use a NOT filter, which will return two or three of the 50 items.  Is there a way to do that ?

 

*Surnames removed to protect identities

 

 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

Hi,

 

The below may appear to be not relevant for your real case because I don't know how color is determined, but as an idea you may consider using regular expressions for search parameters.

Sample pseudocode:

var objects = root.FindAllChildren(['Type', 'Color'], ['regexp: (vegetable)|(fruit)', 'regexp:^(red)'], depth);

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

Community Leader

Re: Use .Find to get all elements that do NOT match the search properties

That is SOO exactly what I was looking for, thanks ! Smiley Very Happy

Syntax correction:

It's 'regexp:[^(red)]' - it was just missing the [] around the ^(red)

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

5 REPLIES 5
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

Hi,

 

The below may appear to be not relevant for your real case because I don't know how color is determined, but as an idea you may consider using regular expressions for search parameters.

Sample pseudocode:

var objects = root.FindAllChildren(['Type', 'Color'], ['regexp: (vegetable)|(fruit)', 'regexp:^(red)'], depth);

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

Community Leader

Re: Use .Find to get all elements that do NOT match the search properties

That is SOO exactly what I was looking for, thanks ! Smiley Very Happy

Syntax correction:

It's 'regexp:[^(red)]' - it was just missing the [] around the ^(red)

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

Hi,

 

That is SOO exactly

Wow, great to hear! Smiley Happy

 

Syntax correction:

May be, needs to be checked.

To my understanding, [red] will match if the string been processed contains either 'r', or 'e', or 'd'.

While (red) should match 'red' exactly.

But I might be wrong and, as I said, exact syntax needs verification.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Community Leader

Re: Use .Find to get all elements that do NOT match the search properties

> Syntax correction

Not a critisism, just an update for future readers of the post Smiley Happy

> While (red) should match 'red' exactly

That's the result I got when testing [red] versus (red)


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
Community Hero

Re: Use .Find to get all elements that do NOT match the search properties

I see, thank you a lot for correction then.

 

[Update]

> It's 'regexp:[^(red)]' - it was just missing the [] around the ^(red)

Ah, got it Smiley Happy

The corrected regexp will match a string that does not contain a token and token equals to 'red'. I.e. effectively regexp will match everything that does not contain 'red'.

Thank you again for correction -- I'll definitely bookmark it.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================