Wrap numbers with numbered tags

I’d like to create a macro that will wrap numbers of the type ‘n’ and ‘n.m’ with numbered tags of the type <x/l> (where ‘l’ is a placeholder for a number).


Zvzv 4.9 szvkv zcvk; vzkzv kvzvclzvkfdll 4.1 cvzvafa, 4.6 szvkv zcvk; vzkzv kvzvclzvkfdll 4.2 cvzvafa.

Should be tagged as:

Zvzv <x1/>4.9<x2/> szvkv zcvk; vzkzv kvzvclzvkfdll <x3/>4.1<x4/> cvzvafa, <x5/>4.6<x6/> szvkv zcvk; vzkzv kvzvclzvkfdll <x7/>4.2<x8/> cvzvafa.

I’ll place the string on the clipboard and I could do some Finding and replacing with regular expressions. But how do I get the numbers 'l’in the tags?


Just realised that numbers can also have 2 digits after the full stop:


Oh, very funny :slight_smile: Discourse suppresses the > and < characters. Okay, the tags look like:


And now I understand why this preview window is visible next to this edit window.

Sorry about that!

Aaargh, and now I had the / placed incorrectly. This is how it should be (I promise):

xxxxxx <x1/>7.1<x2/> xxxxxx <x3/>7.9<x4/> xxxxxx <x5/>7.1<x6/> uxxxxxx <x7/>7.9<x8/> xxxxxx <x9/>7.15<x10/>, <x11/>7.16<x12/>, <x13/>7.18<x14/>, <x15/>7.30<x16/> xxxxxx <x17/>7.55<x18/> xxxxxx

Sadly, numbers of the type:


and even:


occur too.

This displays the result that I'm looking for, except that the tag numbering isn't correct. How can I achieve that?

How do I get this to work?

Tags are numbered by:

In some kind of loop I increase the tag number:


And use the increased number for each new tag:


So I’ve narrowed down my question to: How can I let an S/R action go via a loop?

Hmm, I hope that is the real question ;).

BTW: Peter, great system this Discourse!

So there are really two problems here, the first is to add the tags, and the second is the incrementing tag number, so lets do it in two steps.

You are pretty much there with your regular expression search and replace. Do something like:

Search and Replace Variable with Regular Expression
    Search for: (\d+(\.\d+)?)
    Replace with: <xKMPLACEHOLDER/>$1<xKMPLACEHOLDER/>

The next problem is more challenging. A simple search and replace wont work. You could probably do it with a perl script, and you can also do it fairly efficiently using a For Each action, but its a bit tricky to get it both efficient and correct.

Presuming your text will not be humungous, you can loop while the KMPLACEHOLDER exists, split the text into three parts (before the first placeholder, the placeholder, and after the last placeholder), and then put it back together with the index and then increment the index and try again.

Here is an example:

Thank you very much for your great help, Peter. Highly appreciated.

I’ve published a nice movie on my wiki: