Problem parsing a string with scripting functions

Hi resourceful people,

I'm struggling a bit with an action.
My files are organised in folders with a release ID and a subsequent version ID
For example a release with the ID 12345 and a version ID of 012 would be in a folder named 12345012.

When executing the action I would like it to take the %_directory% name, minus the last 3 digits, and tag it to release_id.
In the same action group it takes the last 3 digits and tag it to version_id.

I have tried a few different scripting functions, but I can't get it to work properly.
When there's only one file it works as intended, but when theres more than one, it fails.
If there is more than one file it continues from the previous file, like:

0101:
release_id: 12345
version_id: 014

0102:
release_id: 12
version_id: 345

I would of course like them all to be tagged as 0101.

My scripting functions:
release_id:
$sub($len(%_directory%),$right(%_directory%,3))

version_id:
$right(%_directory%,3)

I think version_id works properly as long as release_id also works.
I have tried a lot of different functions for release_id by now, and it’s driving me nuts.

Can anyone help me sort this out?

to split the data from _DIRECTORY named 12345014 into release_id and version_id try an action of the type "Guess value"
Source format: $regexp(%_directory%,(\d+)(\d\d\d),$1==$2)
Guessing pattern: %release_id%==%verion_id%