Underscores seem to throw name matching out of whack, trying to match `ABC_123_45_C D_6_7.pdf` where the numbers change

I’m trying to make a Smart Rule that matches files name something like this pattern: ABC_123_45_C D_6_7.pdf where the numbers 123, 45, change, and I don’t mind what is after 6_, I’ve tried a few search term with wildcards but none of them seem to work:

(Using search bar terms to make it easy to test it, I didn’t include name: in the Smart Rule criteria)

  • name:ABC_???_??_C D_6_*
  • name:ABC_???_??_C D_6
  • name:ABC_*_*_C D_6_*
  • name:ABC_*_*_C D_6

Any variation of wildcard that I can think of after ABC_ doesn’t work. Which made me think underscore are throwing something out of whack, then I tried ignoring underscores:

  • name:ABC*C D_6*

Which didn’t work either, so I went for a couple of options just to see if it would “minimally” (as in fewer predicates as possible) work and these also did not work:

  • name:ABC_*
  • name:ABC*

The only search term that worked was not using wildcards at all, like: ABC_123.

Version: 3.8.2, on macOS 12.2.1.

Underscores aren’t indexed, therefore the search is identical to ABC ??? ?? C D 6 * but such generic wildcards aren’t accepted (as your search term currently means "Every name containing ABC, C, D, 6, any word with 3 characters, any word with 2 characters and any word).

This should work for example:
name:"ABC [0-9][0-9][0-9] [0-9][0-9] C D 6"

And this does too as words separated by non-white characters are basically like phrases:
name:ABC_[0-9][0-9][0-9]_[0-9][0-9]_C_D_6

Thanks for the replying on how to make it work. I’ll comment more on how the current system feels to me below.

Interesting, the way you worded is like the order I entered the predicate parts isn’t maintained. Is that a correct read? The way I thought it would work was: “Every name containing ABC, followed by any-3-char-word, followed by any-2-char-word followed by C D 6”.

The search predicate for specific one-digit ([0-9]) seems works as I aspected the any-1-char (?) predicate would. Applying the same meaning explanation from earlier to this digit-based version, it it were consistent/behaved the same, I’d read it as "“Every name containing ABC, C, D, 6, any number with 3 digits, any number with 2 digits.”. Why does the digit-based one maintain the order and can handle the size-based words/numbers but the other one can’t?

Asking the above in regex, why does ABC \d{3} \d{2} C D 6 work but not ABC .{3} .{2} C D 6? Did I misunderstood the ? wildcard in DEVONthink?

The only major difference is that your wildcards (??, ???, *) are too generic, the indexed based search doesn’t support this.