Help with the creation of a Regex or in KM

I have the following string:
123Test1 987Test2 987Test3 987Test4 987Test5
There can be multi occurrences of the above ***followed by one or more digits followed by ***

How in KM can I change to the following? Regex or KM?

Change to the following:
ZZZ123Test1XXX ZZZ987Test2XXX ZZZ987Test3XXX ZZZ987Test4XXX ZZZ987Test5XXX

What is the root problem that you are trying to solve ?

( See: XY problem - Wikipedia )

(It may be that splitting on the string Test, or simply on white space, will simplify the problem)

See my earlier post Capture Text From Front Browser

Ah.. got it.

The problem in that earlier post is that you are keeping the .innerText (the text enclosed by HTML tags)
but shedding the semantics of the tags themselves, which provlde the formatting.

Rather than straying too close to the regex tar-pits, and losing time in a secondary problem, you could:

  1. Extract the full HTML (tags and all, not just .innerText)
  2. Pass the HTML to a shell utility like textutil to derive RTF formatted text from it, or pandoc to derive some other format, like Markdown.

For what it's worth, if you were going to take the string-munging route, you could start with a process like:

Splitting and rejoining.kmmacros (2.1 KB)

Searching online for HTML to Markdown may also yield some useful methods and instruments.


I think I am over my pay grade so will have to rethink.


Here are three methods using only native KM features:

Add ZZZ before- and XXX after- each element in test pattern.kmmacros (9.4 KB)

Macro Image

Edit: Added a fourth method also, using regex, since that was part of your original interest