How to Make Search & Replace Macro Work With Multiple Lines


The attached search and replace with regex macro works fine. My problem is that it works only on the first line of a list.

  1. how could I add an action that specifies "for each line".?

  2. I was thinking of creating 2 macros, one which ignores empty lines and the other that works on empty lines (when I am adding a prefix for example)

Thank you very much

Search Replace w Regex FORUM VERSION.kmmacros (21.3 KB)

Hey @ronald,

You're forgetting that Keyboard Maestro doesn't have multi-line turned on by default.

You have to add (?m) to the beginning of your regular expression.




1 Like

Thank you Chris. The following does not work, even for the first line. Where is my mistake ?

My input in ^(for start of line)

replaced with Monday (on each line)

thanks very much. It above my level. I will attempt to dissect your macro. I am very grateful for your time.

You forgot the parentheses...


sorry but it still does not work. Nothing happens. Would you see any obvious problem. I added clipboard seed but it did not help

User Input I search for ^ (start of line) and replace with monday

thanks and sorry for pestering you

Post the actual macro please.

1 Like

Sorry, I should have done it in the first place.

Search Replace w Regex.kmmacros (22.8 KB)

1 Like


You had placed (?m) in both the search and replace fields – and you had placed a space after it and before the body of the regular expression.

Try mine with the hotkey trigger and see if it works.

Note that the (?m) has been placed in the user-input dialog.

20)Search Replace w Regex.kmmacros (5.5 KB)

Macro Image

Keyboard Maestro Export

1 Like

Hey @peternlewis,

Why does this asynchronous helper macro fail when looking for the user input dialog title, but it works when using the front window exists option?

Since we can't depend upon there only being one KM window open, we need to be able to discriminate.



Peter Test Group Macros.kmmacros (5.7 KB)



1 Like

OK. Now I understand. thanks very much !

1 Like

The Front Window condition explicitly excludes background applications, so it will never apply to the Keyboard Maestro Engine, regardless of any other settings. If you select a background only application by force (like you have done in selecting the Keyboard Maestro Engine), then it will apply to the front application instead.

Ah, so that's what it was doing...

Okay, thanks.

1 Like