# $regexp to return last 3 folders

**URL:** <https://community.mp3tag.de/t/regexp-to-return-last-3-folders/19262>\
**Category:** Support\
**Created:** [August 23, 2017, 8:03pm UTC](https://community.mp3tag.de/t/regexp-to-return-last-3-folders/19262 "2017-08-23T20:03:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mville](https://community.mp3tag.de/user_avatar/community.mp3tag.de/mville/32/9437_2.png) [@mville](https://community.mp3tag.de/u/mville)\
**Post date:** [August 23, 2017, 8:03pm UTC](https://community.mp3tag.de/t/regexp-to-return-last-3-folders/19262/1 "2017-08-23T20:03:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [August 24, 2017, 3:49am UTC](https://community.mp3tag.de/t/regexp-to-return-last-3-folders/19262/2 "2017-08-24T03:49:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mville](https://community.mp3tag.de/user_avatar/community.mp3tag.de/mville/32/9437_2.png) [@mville](https://community.mp3tag.de/u/mville)\
**Post date:** [August 24, 2017, 9:34am UTC](https://community.mp3tag.de/t/regexp-to-return-last-3-folders/19262/3 "2017-08-24T09:34:35Z")

</div>

So it does. ![:huh:](https://community.mp3tag.de/uploads/default/original/1X/f15ee73c0fd9ec3b0db7481f0558638f8ee224ce.gif ":huh:")

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

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [February 9, 2026, 12:26pm UTC](https://community.mp3tag.de/t/regexp-to-return-last-3-folders/19262/4 "2026-02-09T12:26:58Z")

</div>


