$regexp to return last 3 folders

I can return the last 3 folders from a folder path (if the no. of folders is known) using:

$regexp(%_folderpath%,(.+)(\\.+)(\\.+)(\\.+),$2$3$4)

However, what I need, is to return the last 3 folders, regardless of the no. of folders in the path.

I believe this can be done using the $repeat(x,n) function with $folderdepth(%_folderpath%), but my knowledge of $regexp is weak and I cannot get this to work.

Please can someone help/advise?

I do not really understand.
The expression that you offered returns always the last 3 folders, regardless how many more folder levels there are above it.
And if there are less than the 3 folders you get the whole folderpath as there is no hit.
So what was it that you wanted to achieve?

So it does. :huh:

Many thanks for your reply. Sorry for wasting your time here.