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]

**Requires: KM 8.2.4+&nbsp;&nbsp;&nbsp;macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/f/f/ff45f1226bf7c30db6ffb3ded1a8dbf4f17f16e0.kmmacros"> Replace Start of Line Using For Each [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


---


<img src="/uploads/default/original/3X/1/3/13742fdca38fb71024c24cc2ad4793878f5ee5cb.png" width="568" height="1166">

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 regex101: build, test, and debug regex 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]

**Requires: KM 8.2.4+&nbsp;&nbsp;&nbsp;macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/5/5/55da68bf1a074bc3ba3cd6542bf6bbb0e3d22eac.kmmacros">Convert Markdown to HTML [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---

### RegEx Details
* Step 1:  https://regex101.com/r/nMlxiS/3
* Step 3: https://regex101.com/r/S4NkNh/1/
---


<img src="/uploads/default/original/3X/c/a/ca99021a1f02b807729290a4f0bdb24e7a1b96d5.png" width="555" height="1473">

---

### Notes:

The second Replace
![image|522x229](upload://pxy93L9Q06n6JhQOSYmSfsSiPUM.png) 
 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