How to do "If then else with regular expression"

Hey Keyboard Maestro community

My question is super simple, I have a variable that contains 8 or 7, depending o the video. here an example: 10:26:06:03.

I need to tell keyboard maestro that if this variable contains 7 numbers (like this one 1:02:30:14) just add a 0 at the beginning. Example: 01:02:30:14. but I'm not sure how to do that because the numbers always vary.

This is an excerpt of the macro I'm working on!

Set Variable to Text.kmmacros (3.1 KB)

Thank you very much in advance

Perhaps for example:

  • change the condition type in the pull-down at left to matches
  • use the regex ^\d\d: (i.e. starts with two digits and then a colon)

It works perfectly, thank you!

by the way, what is this ^ symbol means for keyboard maestro?

Not specific to KM – in regular expressions generally:

  • ^ matches the start of a line
  • $ matches the end of a line

That depends on the RegEx flag/options setting for multi-line: (?m)
Without that setting those match only the START of the string and END of the string, regardless of how many lines in the string.

2 Likes