Tinderbox Forum

Wildcard search in query

Hi there, is there a way to conduct a wildcard search, e.g. $Capabilities.comtains (*Password). I want to search for a specific word not a complete phrase.

Yes, both String.contains() and String.icontains() allow regular experssion (regex) search. However, if testing List or Set type data you can only match to whole list items - see more. So, we’ll assume $Capabilities is a String-type and we want a case-insensitive match to the sub-string “password”.


Here regex are not needed as we have a literal string and .icontains() deals with case. We don’t need to worry about the other parts of the string. Only if you need to deal with placement of the term (e.g. at the end of the string, or in combo with other character, or if a back-reference is needed would you need a regex. This does the same as above but uses more CPU cycles to do so there is nogain:


The .* regex just means ‘zero or more characters of any type’ so would still match if the only characters in the target were “password”. In fact, I suspect when you use the first term that is how the app deals with it so my observation on CPU use may be moot! The main point re regex (contains, icontains, replace, etc.) is if you can use a more precise operator—not the case here—such as == or != then try to do so.

If you’ve several real phrases to test, as in yuo “passord” above, in an agent you can set $MyString as a Key Attributes in the agent and add your search term there. Then use the query:


The search term is not quoted as we’re telling Tinderbox to replace our literal or regex match string with the string stored in the $MyString belonging to the agent. Change the agent’s $MyString, you change the query. Neat!

Does that help?

This is perfect. You had me up to the $MyString part. I don’t understand how to do that with an agent.

With an agent? The secret is use of a designator, this case ‘agent’. Let’s unwrap the layers. If you use the query:


instead of checking $Capabilities in each note against a string like “password”, the query reads the value $MyString in each note it checks and uses that string value for the icontains() test. Cool, except now if you want to check 1,000 notes, you’d have to set the first string test value in every note. Then set the next test string in al those notes etc. Way too much work. But if we use:


for each note checked the value of $MyString in the agent is used as the test value. So, set it once in the agent and all notes get the same test: change the agent’s $MyString, you get a different test, etc.

How you set the agent’s $MyString value is up to you - there are so many ways: as a Key Attribute for the agent, via Get Info, QuickStamp, etc. Choose one you like.

It really is that simple.