ronald
January 11, 2023, 11:36am
#1
Hello,
The attached search and replace with regex macro works fine. My problem is that it works only on the first line of a list.
how could I add an action that specifies "for each line".?
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)
ccstone
January 11, 2023, 12:31pm
#2
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.
-Chris
2 Likes
ronald
January 11, 2023, 6:50pm
#4
Thank you Chris. The following does not work, even for the first line. Where is my mistake ?
Thanks!
My input in ^(for start of line)
replaced with Monday (on each line)
ronald
January 11, 2023, 6:51pm
#5
thanks very much. It above my level. I will attempt to dissect your macro. I am very grateful for your time.
ccstone
January 11, 2023, 8:08pm
#6
You forgot the parentheses...
(?m)
ronald
January 11, 2023, 8:18pm
#7
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
ccstone
January 11, 2023, 8:20pm
#8
Post the actual macro please.
1 Like
ronald
January 11, 2023, 8:24pm
#9
Sorry, I should have done it in the first place.
Search Replace w Regex.kmmacros (22.8 KB)
1 Like
ccstone
January 11, 2023, 9:03pm
#10
Okay...
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
1 Like
ccstone
January 11, 2023, 9:25pm
#11
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.
TIA
-Chris
Peter Test Group Macros.kmmacros (5.7 KB)
1 Like
ronald
January 11, 2023, 9:38pm
#12
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.
ccstone
January 12, 2023, 12:39pm
#14
Ah, so that's what it was doing...
Okay, thanks.
1 Like