Skip navigation

Spotlight "?" match single character wildcard doesn't work

190 Views 0 Replies Latest reply: Jan 6, 2013 4:24 AM by Stati RSS
Stati Calculating status...
Currently Being Moderated
Jan 6, 2013 4:24 AM

Hi Everyone,


today I run into the following problem:


I wanted to select all files in a directory, which have the following name: "4e-[2 characters].jpg", e.g "4e-01.jpg" or "4e-12.jpg", but no files with 3 numbers like "4e-001.jpg" or "4e-012.jpg".


So I created a spotlight raw query in the form kMDItemDisplayName == "4e-??.jpg". This query did not return any results. After I changed the query to kMDItemDisplayName == "4e-*.jpg" it returned all files, those with 2 numbers and 3 numbers inside the filename. The same happened when I changes kMDItemDisplayName to kMDItemFSName.


The behavior was identically in the Finder with a raw query and in the Terminal, when using mdfind in the directory where my files reside.


mdfind -onlyin . "kMDItemDisplayName == '4e-??.jpg'" or mdfind -onlyin . "kMDItemFSName == '4e-??.jpg'"


didn't return results.


mdfind -onlyin . "kMDItemDisplayName == '4e-*.jpg'" or mdfind -onlyin . "kMDItemFSName == '4e-*.jpg'"


again returned results, but the wrong ones for my purpose.


I tried also escaping the "?" character, but it didn't help.


Am I missing somtehing? The documentation says that the question mark character matches one single character.


Thanks in advance,



MacBook Pro with Retina display, OS X Mountain Lion (10.8.2)


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.