Squeezing – Deduping.
Both the source text and the pattern seem to be pretty straightforward. The source text is of the form (I've numbered the lines for easier understanding; they're not meaningful):
#0: A line of text
#1
#2: Another line of text
#3:
#4:
#5: Another line of text
#6:
#7: Yet another line of text
#8:
#9:
#10: Your boring line of text.
#11:
#12: More of the same.
#13
#14: Will this never end?
#15
#14: Keeps giving.
I want to remove duplicate contiguous blank lines to make the formatting uniform, working them with the Search-and-Replace action.
My neat and terse regular expression is as follows:
Search for (?m)(?-s)(^\s*\n)\1
and
Replace with $1
No matter what combination of characters and flags I use, KM cannot find the pattern. I confirmed the regex to work on Regex101 and in the Mac app RegExRX by Mactechnologies.
Regex101:
RegExRX:
However, when I feed KM the same expression, I get either empty capture variables (i.e., undefined) or the entirety of the target text. The crux of the problem is that there's no way to foretell what the KM regex engine thinks line endings are. Are those "$" or an intermingling of "\r" and "\n"?
RegExRX utilizes PCRE 8.33, but the version of the app (1.8) I use on one of my older machines was released in 2013. Regex101 indicates PCRE2 and PCRE, which translates to PCRE 10.43 (2024) and PCRE 8.45 (2021). The EOL of Keyboard Maestro 6 was in 2015, two years later than RegExRX.
You'd think that KM would catch up. What PCRE iteration does it conform to?
However, even if the difference between PCRE versions affects the development, is backwards compatibility on the list? The immutable segment covers the overwhelming majority of scenarios.
Most importantly, is this action viable for accomplishing the simple tasks I've shared?