Search and copy text from text document


I’m new to Keyboard Maestro and was wondering if there is a simple way to search for every instance of a string of text in a document and copy it into a new text document?

Many thanks

I would expect that this can be done in KM using RegEx, but we need more details please.

Could you please provide a detailed example (using real data) of what you are trying to achieve:

  • Source data text
  • Source data app
  • Data output to new document
  • App of new document

I am confused by your statement to “search for every instance of a string of text in a document and copy it into a new text document”. If it is the same string, you would just be copying the same string every time, so you new document would have multiple copies of the same string. Is that what you want?

Meanwhile, you might look at this macro. It uses a very complex RegEx pattern to copy multiple lines from source document to the clipboard.

MACRO: Get List of RegEx Capture Group of Multiple Matches

It’s a .txt file in Sublime Text and I want to output the text to a new .txt file in Sublime Text.

I’m looking to find every instance of a string of text (url scheme) that looks something like this:


I’m wondering if it might actually be easier just to do this is Sublime Text, but as it’s something I do often I’m thinking it might be nice to have a macro that saves me some time.


Something like this should work:

1 Like

Thanks Tom! I’ll give this try tonight.

In Sublime Text you can do a Find > Find All, ⌘C copy the results, and ⌘V paste the results into a new document, one line per result. Sublime supports regular expressions in Find / Find All.


BBEdit and TextWrangler also have a great RegEx Find/Replace (called “Grep”), in case anyone doesn’t have Sublime Text.

1 Like

Thanks guys that did the trick. Sadly no need for KM this time.