How Do I Extract Dates From Multi-Line Text?

Need an update for the workflow. My previous example provided lines with the dates in them. How can I go about extorting the date if there is a bunch of text between the lines?

1/10 - May 14, 2019

Bunch of text. Bunch of text
Bunch of text
Bunch of text
Bunch of text
Bunch of text

2/10 - May 24, 2019

Bunch of text. Bunch of text. Bunch of text.
Bunch of text

3/10 - June 3, 2019

When I check the RegEx pattern at, everything works as expected.

When I use KM, I get a RegEx error when I try to execute the workflow. Any idea why?

Session Dates.kmmacros (11 KB)

Your new workflow is significantly different, and thus should be posted as a new topic. I have moved it for you this time.

This requires a different approach, to first extract ONLY the lines that contain a date, and then extract the date from that line.

The same RegEx can be used in both the For Each and the RegEx Search:

for details, see

Here's a simple macro that does ONLY the extraction. You will need to use/adapt to your specific workflow:


Example Results


MACRO:   Extract Dates from Multi-Line Text [Example]

~~~ VER: 1.0    2019-08-12 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9d9 on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Extract Dates from Multi-Line Text [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.



Hey @slyfox,

There's nothing wrong with using regular expressions for this sort of job, but it's generally easier and more flexible to use Apple Data Detectors.

Here's the output:

I can change the output format to anything you want with the addition of a bit more code.


Extract Dates from Text Using Apple Data Detectors v1.00.kmmacros (6.8 KB)
      ⇢ Created with KM v9.0.

Hey Chris, one issue that might occur with Data Detectors looking at all text in the source is if some of the "bunch of text" contained text that could be construed as a date, like say "8/13", or even an actual date when then only dates you want are in the "header rows" as defined by the RegEx.

Yep, that's another thing you'd have to do.
May I suggest that you allow for setting of date format in KM variable, using the ICU format, and then if that variable is empty/missing, just output in a standard format (I'd suggest the ISO format).

Having said all that, I really like the ASObjC Data Detectors, and use it often.

@JMichaelTX Thank you for your solution.

Any idea why I am getting a different result from your picture? I get this:

May 24, 2019
June 3, 2019

I figured out the solution to my original problem of extracting dates from text and pasting them into a numbers column.

Thank you !

Keyboard Maestro 8.2.4 “Extract Dates from Multi-Line Text [Example]” Macro

Extract Dates from Multi-Line Text [Example].kmmacros (4.7 KB)

Looks like you have NOT entered the KM Variable Tokens correctly.
You left out a % between the variables.

They should be: