Get Number From Text

Hi there,
I'm relatively new to Keyboard Maestro and had a question about extracting the number from a file. I'm working with audio files where I need to extract the tempo information ie (100bpm, 68bpm, etc) but all my files are already named this way:
" PGT_RT 16_TRK3_120bpm_v1.0_2MIX"
What would be the best way to select the file, process just the text in the name and get only the number (in this case 120) from it and copy it to the clipboard so I can paste in a separate app? Thanks so much for your help!

Oh. Good question. Should be easy to fix this. Although it might take me ten minutes to come up with the solution.

Getting the number from the file name is very easy using RegEx:
_(\d+)bpm

You can use a KM For Each action with either a Finders Selection collection OR a Folder Contents collection.

In the For Each, set the loop variable to "Local__FilePath", and then you can use this Search Action to extract the tempo.

image

Let us know if you need further help.

Hey, my ten minutes weren't up. Good job, JM.

Thanks so much! It seems to work but I'm trying to paste the result the Local_Tempo and can't seem to get it. Do I need to set the variable to the system clipboard and then paste or is there a different/easier way?

Perhaps you didn't paste the results of Local__Tempo into the clipboard at the end of the macro.

Thank you so much! You've both been immensely helpful and it's all working great now! I really appreciate everything!