Regex ^ and $ matching fine in regex101.com but whopping it up in kbm

As far i see the matches in regex101.com, ^ matching works fine.

I start with this text

But i end up with:

after using this search and replace macro...

sub Search #$ and replace to

<:h2>.kmmacros|attachment

(2.9 KB)

Why is it not matching as in the regex101?

What i wish for it to end with is:

(so that means i also have to make replacementes for æøå, but that should be easy to do.)

Thanks for any help or suggestions!

Looks like you have uncovered a KM bug. I have just submitted this bug report:
KM9 Bug Report: RegEx Change at Start of Line Inserts Wrong Characters

Since the first action of your Macro failed due to bug, I did not look further.

However, there may be some work-arounds, like this:

Example Output

image

MACRO:   Replace Start of Line Using For Each [Example]

~~~ 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:

Replace Start of Line Using For Each [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Update: It is NOT the bug I first reported. The problem you are seeing is because the Search and Replace "Replace with" field, in your macro, actually has two lines in it:

image

So, starting from the beginning, using the source text from your https://regex101.com/r/nMlxiS/2 post, I have found the following macro to do generally what you are asking for. However, the text in the final result image you posted does NOT match the source text. So, I'm not sure exactly what you want. But this should at least get you started.

Be careful to NOT paste text into the Search and Replace Action. Be sure to just type it in.

Example Results

MACRO:   Convert Markdown to HTML [Example]

~~~ 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:

Convert Markdown to HTML [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


RegEx Details



Notes:

The second Replace
image
is there to replace TAB and other characters in this substring:

har Oslo 	opplevd

with one SPACE.

I am at a loss of words @JMichaelTX.... :yellow_heart:

Does that mean my macro works for you? :smile:

1 Like

Can you use the 'insert text by typing' and the %clipboard% Variable to do this? I see why one has to avoid pasting in 'invisible' characters.

That it does! And I´m in awe at the persistence you show for helping me and all the other users that are in need.

2 Likes