Stripping time from the end of a date string

I need to change a text string using KM's find and replace. I want to change from:

date Friday October 13, 1960 at 01:02:03 AM


October 13, 1960

thanks in advance

Larry Wilson

As the whole line of text has pieces of text separated by spaces, you can use those spaces as your "delimiter" to split the line into pieces and then use pieces 3, 4, 5 to get your shortened line.

No doubt there is Regex to do this, but you can also just do using Keyboard Maestro's ability to split a Variable using any "delimiter" (in this case, the space symbol).

The syntax for this is the Variable name followed by a number in square brackets, followed by the chosen delimiter (in this case a space).

So, if your whole line is stored in a Variable called, for example:


To get piece 3, would be


And the syntax to use that in a text field:

%Variable%LOCAL__Text[3] %

As the space symbol will get stripped out when the line is split, you need to add a space back in between each piece, when you reassemble the shortened line.

%Variable%LOCAL__Text[3] % %Variable%LOCAL__Text[4] % %Variable%LOCAL__Text[5] %

EXAMPLE Split Text at Spaces.kmmacros (3.0 KB)


It's a very good question, and it would be helpful if others could find it later.

I've edited the title to make it a bit more findable.

(The number of threads essentially entitled "regex" is huge, and in the bulk of them, the real question is masked by an expression of the XY problem)

1 Like

Thanks very much to both @Zabobon and @rlivingston for the solutions. I wish I could mark both methods as the solution but discourse won't let me. I learned quite a bit from both of these solutions.

What a great forum!

Larry Wilson

1 Like