8

Does anyone know where I can find the docs describing Regex parsing capabilities of macOS search fields?

What I mean, I'd like to read about the regex syntax rules that are allowed and parsed by the search field. For example, what I didn't know until today that, in macOS Preview (or any other application with a standard search field, guessing) we can use input like this:

"\s" AND "an" AND "\s"

This works and hints that search fields interpret more regex then we know, and this is what I want to read/find out about. The example above searches for "an" with one trailing and leading whitespace character \s within a opened document.

I'd like to know more about those grouping rules and regex characters wrapping/escaping so it can be correctly parsed. Also does this format of input apply to systemwide search fields of any application?

I can't find any docs describing these features and was found only this on developer.apple.com library instead.

Below you can see an example of default search behaviour for a "an" word within a PDF document, it shows all "an" occurences in the results, regardless if you put a space before the "an" word, so your input is " an "

enter image description here

When we put "\s" AND "an" AND "\s" into the search field we get the more desired search result

regex input search field behaviour

This makes a huge difference for searches containing common words!

In short: I'd like to know more about the functionality you see above. Where can I find any (official) documentation about it?

The answers provided (so far) are not answering my question, thank you for them though - aggregating more related information is good.

  • Will this link be of any help to you? – Denis Rasulev Dec 27 '16 at 13:43
  • Hi Denis, thank you for the link- but this is more or less the posix regex manual ;-) and if you look carefully into my example above- its not posix regex- since the common syntax isn't working and that is why the question is here. Im not sure if words like AND OR are in posix regex (correct me, if i'm wrong) anyways. That being said- I can't find the specifics of the syntax for this kind of search field. It is (probably) an instance of developer.apple.com/reference/appkit/nssearchfield#overview (guess) but I can't dig out the regex specifics. – PJJ Dec 29 '16 at 6:28
  • Are you sure that we’re talking about regex here? I tried your example in Preview, and a few regex variations, but none of them seemed to behave as a proper regular expression. That doesn’t answer your question, but might help in looking in the right place. – Manngo Jan 17 '17 at 11:13
  • Yes, you are right - and this is what I want to find out! Where is a document describing what kind of syntax is parsed and how? It's not posix regex, but it's regex-ish enough, so what is it? :) – PJJ Jan 17 '17 at 22:24
2

I don't know if you discovered this already but you just need to click on the magnifying glass in the search field, it has a little down-pointing caret which is the clue, see this screenshot:

enter image description here

After clicking choose Insert Pattern and you get a range of options:

This is basically user-friendly regex, i.e. you get tokens you can easily arrange into quite powerful search patterns.

enter image description here

The example in the screenshot is TextEdit however this option doesn't appear to be available in Preview.

  • Hi- thank you for the long answer, BUT this is TextEdit you are showing... not the system-default search window like the one in Preview option, therefore it is not the answer i'm looking for. The search Window I mean is (highly probable) an instance of developer.apple.com/reference/appkit/nssearchfield#overview – PJJ Dec 29 '16 at 6:15

You must log in to answer this question.

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