KM9 Bug Report: RegEx Change Accepts Multiple Lines Pasted, but Shows ONLY One Line


KM9 Search and Replace with RegEx Bug

EDIT: 2019-11-02 14:33 GMT-5

KM9 is replacing with characters NOT called for in Replace with field.

Steps to Reproduce

Search for:

Replace with:

Example Output


Expected results were confirmed with:

MACRO:   KM9 Bug -- Replace Start of Line @TEST

~~~ VER: 1.0    2019-11-01 ~~~
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:

KM9 Bug -- Replace Start of Line @TEST.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.

There is a bug, but it is a different one than I thought. :wink:

The OP results occurred because the KM Search and Replace Action allowed multiple lines in the "Replace with" field, although it showed only one line.

If you click in the "Replace with" field, and Select All, then you will find this:


If I clear the "Replace with" field and type in "<p>", then it works as expected:


So, the bug is allowing multiple lines in a field that is designed to take only one line.

This is not a bug, it is just the way it is. Almost every single line field in the Mac will not accept pressed returns, but most will accept pasted returns, and such returns will result in largely invisible text in there.

This is really no different to a replacement text that has spaces at the end.

There is nothing wrong with having a return character in your replacement text.

Maybe those shouldn't be single-line text fields?

I mean, using the (?x) flag, you can paste in commented regexes like this (like, say, you found something you could use on StackOverflow or elsewhere):

# Match a 20th or 21st century date in yyyy-mm-dd format
(19|20)\d\d                # year (group 1)
[- /.]                     # separator
(0[1-9]|1[012])            # month (group 2)
[- /.]                     # separator
(0[1-9]|[12][0-9]|3[01])   # day (group 3)

and only one line at a time would show in KM. And you can't even type that regex in at all because you can't type multiple lines. That doesn't seem like the way things should be.

Or it would even be useful to be able to type in multiple line replacement patterns.

And, really, that kinda reduces the utility of the (?x) flag. You can't really take full advantage of it because you either can't type in multiple lines or will only see one line at a time of a pasted-in pattern, which makes it difficult to study a pattern as a whole.

Well, Peter, I hope you can appreciate how this can cause serious problems for the user.

  • Both myself and @Isak were completely confused and mislead by this behavior, which resulted in considerable wasted time. For me, at least an hour. Not acceptable for a tool that is supposed to SAVE me time.

Evidently you do know how to design a single-line text field so that it only accepts one line:
The "Set Variable to Text" Action:


Note how the Variable name is displayed in RED, and nothing is actually entered for the Variable Name.
When I run the below macro, I get this:





So, surely it is clear to you that some change is needed on the Search and Replace and Search with Regex Actions to address this issue.

At the bare minimum, I suggest that you treat both the "Search for" and "Replace with" fields the same as you do with the "Set Variable to Text" Action.

OTOH, I agree with @roosterboy above, that accepting multiple lines in these fields could be useful.
If you do accept multiple lines, then the field should auto-expand to show ALL lines.

Thanks for your consideration of this change request.