Searching for words

I recently got asked by a relative to search for different words in a text. “Easy” I answered and was thinking of either a simple Python script or a regexp in BBEdit.

Then came the next sentence, “I need to do it on my phone” and things got way more complicated for me. But I thought that perhaps it can be done in Drafts, and I’m sure it can be done but unfortunately Drafts is something that is a pretty unknown to me.

From what I can see Drafts support regexp but it looks like searches can’t be saved. When I looked at shortcuts it seem like search doesn’t support regexp.

So I’m looking for advise on how to best do the following: the relative want to search for a list of words, and if any of those words shows up in a text they should be highlighted or some similar. Trying to figure out the simplest way of doing this for my relative I imagined putting each word on a separate line in a note (to make it easy to modify the list) and some kind of script that took this list and searched the text in another note. But I have no idea if this is the best way to do it, or even how to do this in drafts.

So any pointers for the best way to do this would be very much appreciated.

I spotted this earlier today, but have been travelling or busy with other things most of the day, so I didn’t get chance to look at it in more detail until this evening, and spent a few hours putting something together.

Other than the phone and Drafts aspect, it was this that got me thinking. It sounded like this was purely a find operation (rather than edit), and the “highlighting” aspect also piqued my interest as the Drafts editor doesn’t really align itself to that sort of thing unless you start modifying the text and applying syntax highlighting - which sounded like it would be going in the wrong direction.

Instead I started to think about processing the text and doing highlighting of search criteria in the ways many web sites do. Fortunately, there are libraries out there that do exactly that sort of thing, so all it should take is a bit of a wrapper for Drafts to take advantage of that. And so that’s what I tried to do.

It comes down to one action, but I’ve built a small action group around it to illustrate how to use it as it has a fair bit of flexibility to it.

In the action group, you’ll find a set of documentation/instructions, which are reproduced in the action directory.

You’ll find a couple of actions that generate sample drafts to show off the examples, as well as a set of examples.

There is a clonable action which you can duplicate and tweak the settings of to build your own standard searches.

Finally, there is a helper action that does the integration work with a library called mark.js.

In the examples you will find ones that use predefined text strings and regular expressions as well as ones that display a prompt and allow you to enter a search string or regular expression. In the examples, you will also find one that will search for text strings that are maintained in a draft (each line defines one string), and one of the sample drafts will generate a sample draft for you to work with the sample text the other action in the same section generates.

Hopefully, this covers the sorts of cases you were envisaging and allows you to quickly and easily build out your own highlight actions for your relatives. With any luck, others will find it useful too.

Sorry about the delay in answering - life happened.

Huge thanks, hopefully this will help me create something that makes my relative satisfied.

Once again, thank you.