Request: Add Switch to KM Search/Replace to Turn Global Matches On/Off

Continuing the discussion from Keyboard Maestro Regular Expression Bug? Trim Whitespace from Start and End of a String:

Use Cases -- How We Would Benefit From this Request

  1. Replace Only the First Match in a Complicated String
    • There are many times where we do NOT want to replace ALL of a given text (or Regex pattern) in a string.
    • For example, the header portion of a long text document (string) where I just want to replace some key terms in the header, like "Author", but NOT in the body of the document.
  2. Make sure the string end with only one LF, whether the source string has none, or many LF at the end.
  3. Anyone who has ever used BBEdit to clean up a document will understand this.
  4. While we could use tools outside of KM to do this, the point of KM is to make it easier for everyone, including those who don't script, and don't have other tools.
  5. I want to use KM to automate the routine cleanup of documents/email/downloads that I receive.

@peternlewis, please consider this request in the broadest terms of how it might be used.
Thanks.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Every language/app I know of, that supports RegEx, allows the user to perform a Regex Replace with Global matches either on or off.
KM does NOT provide this, and thus produces unexpected results for this simple use case:

Use Case #2

  • Ensure that String Ends with One, and Only One LF

In this example, I will use a bullet • in the results to make it easier to read.

Reference Case: Regex101.com

Case 1 and Case 2

image

BBEdit Works the Same way

Demo_BBEdit-Replace-AN

KM Example Results

image

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Make sure text ends with One an Only One LF

-~~~ VER: 1.0    2021-06-18 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Make sure text ends with One an Only One LF.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


1 Like

This one would be useful. Very useful.

Though I'm not against this, I hope Peter puts this on the back burner, because there are many things that are more important. An easy workaround is to use the "Apply a BBEdit Text Factory" action.

Each of us have our own priorities, our own preferred new features.
I did not ask Peter to prioritize my request. That is his job to determine which new features will benefit the most uses and/or might attract new KM users.

2 Likes

Updated my OP to add the above.

Noted.

2 Likes

If it's true that you have come around to that way of thinking, then that is somewhat heartening. You certainly didn't hold that view in the past, when you would dismiss my feature requests as unworthy of Peter's attention simply because you didn't think you would ever use them (and erroneously presumed that no one else would, either).

To be clear to all, my "way of thinking" about enhancement requests has not changed. I have always thought that it was up to Peter "to determine which new features will benefit the most users and/or might attract new KM users."

We are now several posts off-topic. I hope we can stop now. If you have any complaints about me, please feel free to communicate them privately to Peter.

Done for the next major version.

5 Likes

Many thanks, Peter.
:+1:

1 Like