Reformatting in KM

Hey there,

I'm looking to take the following text:

3m04 - Buy Her The Dog [0:35]

And reformat it so it comes up as:

3m04_BUY HER THE DOG

So far I've copied the text and using Search Using Regular Expression, I can't seem to figure out how to capture just the "3m04" and "Buy Her The Dog" so I can reformat the" - " to just "_". I'm a beginner still with Regular expressions and KM but is it possible to do the above? Thanks!

Here's an example that should do the trick.
Please let us know if this works for you.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example Output

image

MACRO:   Extract Fields from String and Recombine [Example]

**Requires: KM 9.0.2+   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/0/1/01ddab522d9c3f26c07242648b0afffd7946ebda.kmmacros">Extract Fields from String and Recombine [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---

### Release Notes
1. This makes use of the new [Text Case Conversions ](https://wiki.keyboardmaestro.com/manual/Tokens#Text_Case_Conversions) provided in KM 9.0.
2. It uses this RegEx:
   * `^(.+?)\h+-\h+(.+?)\h+\[`
   * For details see https://regex101.com/r/XDJCkl/1/

---


<img src="/uploads/default/original/3X/5/a/5a5fe3352613996bd3a2b71f9cd02e542c6d7b44.png" width="515" height="983">
1 Like