Have you tried a simple "Search and Replace" rather than a regex?
Depending on the source of the text you may have to replace %LineFeed% with %Return%.
You can then either always, or conditionally, strip the last character to remove the trailing :
Otherwise you should post your actual macro (not an image of it) so people can check Action options, spot invisible characters, etc. Because your regex Replace seems to be working for me...
(() => {
"use strict";
// lines :: String -> [String]
const lines = s =>
// A list of strings derived from a single string
// which is delimited by \n or by \r\n or \r.
Boolean(s.length) ? (
s.split(/\r\n|\n|\r/u)
) : [];
return lines(
Application("Keyboard Maestro Engine")
.getvariable("sampleRows")
)
.join(":");
})();
I went with the JavaScript option. I was trying to do regex the Keyboard Maestro way, but perhaps it is just easier to drop out into a scripting language.
This may have been deliberate, but did you realise your regex had two lines?
\R(?=\d)
\r
Going from your screenshot, I was only using the first -- which is possibly why mine worked (and is certainly why you should always post a the actual troublesome macro and not just an image of it!).
No I did not! I kept fiddling with the visible line. It never occurred to me this was a multiline field. Is this a bug or a feature? Two notes to self:
Post the macro, when you ask for help.
When you are having problems, remember to clear fields and start with a fresh query.
If it's the first you can right-arrow through to the next line(s) and delete.
The other, properly nerdy, way to check is to right-click the action, "Copy as XML", and paste into a text editor. Lines that start tight to the left margin are part of multiline strings and really easy to spot -- in this case:
And there's always room for an AppleScript version... Useful because paragraphs of is line-ending agnostic -- if you want to prove that for yourself, set the text to a mix of old-Mac, Unix, and Windows line-endings such as
I'm sure reverse of rest of reverse of aList isn't the most efficient way of dropping the last item of a list (in this case, to deal with a trailing line-ending) but I use it because it makes me smile every time
--------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2016/05/08 00:59
# dMod: 2023/03/25 20:10
# Appl: AppleScriptObjC
# Task: RegEx Find-Replace Handler.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Find, @Replace, @Text, @RegEx, @cngStr, @Change
--------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
--------------------------------------------------------
set dataString to "
125429
125426
125429
125426
"
set newStr to its cngStr:"\\A\\s+|\\s+\\Z" intoString:"" inString:dataString
set newStr to its cngStr:"\\R" intoString:":" inString:newStr
--------------------------------------------------------
--ยป HANDLERS
--------------------------------------------------------
on cngStr:findString intoString:replaceString inString:dataString
set anNSString to current application's NSString's stringWithString:dataString
set dataString to (anNSString's ยฌ
stringByReplacingOccurrencesOfString:findString withString:replaceString ยฌ
options:(current application's NSRegularExpressionSearch) range:{0, length of dataString}) as text
end cngStr:intoString:inString:
--------------------------------------------------------
However โ the character in question is not a return it's a linefeed. (macOS converted from carriage returns to linefeeds long ago.)
You're better off using the \n meta-character which will be properly interpreted by KM in the plain string find/replace action, because you can eyeball the replace string and not have to guess, test, or document it.
If you really needed a return character that would be: \r