Well, I think you may find that a lot of people here recommend the Regular Expression route, though that requires learning the basics of Regular Expressions.
regexRoute.kmmacros (3.7 KB)
and my personal feeling is that if you are going to learn a language like that, you might get more flexibility and less fiddle from learning a fuller language like JavaScript or Python
JS route.kmmacros (2.1 KB)
and if, very sensibly, you would prefer to avoid learning any language beyond the Keyboard Maestro actions themselves, then I would recommend:
- Studying @peternlewis 's response lower down in this thread: How Do I Get the Position of a Character in a String using KM Actions? - Questions & Suggestions - Keyboard Maestro Discourse to find out how to get the position of the next hyphen, and
- action:Substring of Variable or Clipboard [Keyboard Maestro Wiki] to find out how to use position indexes to extract sub-strings.