10

In my Finder search criteria, when I am filtering on a text field I have various options. One of them is "matches", and the other is "contains", but aside from establishing that they are indeed different I am unclear on what exactly either of them mean (contains go matches a file name libpng.o for example, which I also find confusing).

enter image description here

2 Answers 2

9

I have found that an easy way to decipher exactly what Finder means by a query is to save it as a saved search and then inspect that file with a text editor. So in your case open up Finder and make a search for matches 'go' and save that as a saved search, and do the same for contains 'go'.

If you do that, you'll see that matches 'go' produces this search pattern:

(kMDItemDisplayName = "go*"cdw)

whereas contains 'go' produces this search pattern:

(kMDItemDisplayName = "*go*"cd)

kMDItemDisplayName means that you're trying to match something to the displayed name of the file.

Each of the letters in cd and cdw are so called value comparison modifiers:

  • The letter c means that the comparison is made case-insensitive (i.e. A and a are considered the same).
  • The letter d means that the comparison is insensitive to diacritical marks (i.e.è and e are considered the same).
  • The letter w means that the comparison is word-based, and that the comparison detects transitions from lower-case to upper-case.

You can find the documentation of the value comparison modifiers in Apple's documentation.

So in your scenario matches 'go' means that it will search for files where the name has a word inside it that starts with the string go (i.e. there could be any suffix to the string in the word) - ignoring case and various marks.

Similarly, contains 'go' means that it will search for files where the name has the string go somewhere inside it (i.e. there could any prefix or suffix to the string) - ignoring case and various marks.

3
  • 1
    Interesting, from testing it appears that MacOS thinks the period in libpng.o is a diacritical mark.
    – orlp
    Mar 21, 2022 at 15:00
  • Yes, it is simply disregarded in the matching - so "g.o" matches "go" (star g o star) in this particular case.
    – jksoegaard
    Mar 21, 2022 at 15:07
  • There is an additional twist for multi-word searches: Spotlight treats contains go fish as looking for the specific string entered (with the space), but matches go fish is treated as (matches go AND matches fish). Oct 17, 2022 at 13:40
-2

matches is the exact meaning, so if only one char (even hidden ones) is invisible, it will not match.

contains is more flexible, and will match also substrings

1
  • 3
    This is wildly imprecise, matches isn't an 'exact match', e.g. go will match goals, myGoals but not mygoals.
    – orlp
    Mar 21, 2022 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .