# Problem with Sets in $regexp

**URL:** https://community.mp3tag.de/t/problem-with-sets-in-regexp/12078
**Category:** Support
**Created:** [June 1, 2011, 11:09pm UTC](https://community.mp3tag.de/t/problem-with-sets-in-regexp/12078 "2011-06-01T23:09:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![TAC109](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/848f3c/32.png) [@TAC109](https://community.mp3tag.de/u/TAC109)
#### Post date: [June 1, 2011, 11:09pm UTC](https://community.mp3tag.de/t/problem-with-sets-in-regexp/12078/1 "2011-06-01T23:09:23Z")

</div>

I'm having a problem with $regexp when I use a set (e.g. "[\w\s]" or "[^\\]") in a regular expression.

My music is structured with the genre as the 2nd directory after root  
e.g. S:\Tom\Rock\Genesis etc\Mike & The Mechanics\1990 Interview\01 Mike Rutherford.mp3

I've set up an action group with a Format Value entry, Field GENRE,  
Format String: $regexp(%\_folderpath%,^.{3}\w+\\(\w+)\\.+$,$1)

This works correctly, returning 'Rock', but it only handles single words in the first directory name. When I change it to  
"$regexp(%\_folderpath%,^.{3}[\w\s]+\\(\w+)\\.+$,$1)" it returns the complete %\_folderpath%

The preferable solution "$regexp(%\_folderpath%,^.{3}[^\\]+\\(\w+)\\.+$,$1)" also returns the complete %\_folderpath%

Am I doing something wrong or is there a bug?

TIA

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [June 2, 2011, 4:22am UTC](https://community.mp3tag.de/t/problem-with-sets-in-regexp/12078/2 "2011-06-02T04:22:29Z")

</div>

> [@TAC109](#):
>
> ... Am I doing something wrong ...

Hmm, yes, please study the Mp3tag scripting language in detail, to get to know the exceptions.  
Some characters are designed to have a special meaning, e. g. the square brackets.  
They need to be escaped when they should be used in their literal meaning in a subsequent language like the Regular Expression Language.

**$regexp(%\_folderpath%,'^[A-Z]:\\\\(.+?)\\\\(.+?)\\\\.\*$','$2')****$regexp(%\_folderpath%,'^..\\\\(.+?)\\\\(.+?)\\\\.\*$','$2')****$regexp(%\_folderpath%,'^..\\\\.+?\\\\(.+?)\\\\.\*$','$1')**

Each regular expression returns the second foldername from the left side.

DD.20110602.0822.CEST

---

<div class="post-metadata">

### Author: ![TAC109](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/848f3c/32.png) [@TAC109](https://community.mp3tag.de/u/TAC109)
#### Post date: [June 2, 2011, 10:04pm UTC](https://community.mp3tag.de/t/problem-with-sets-in-regexp/12078/3 "2011-06-02T22:04:01Z")

</div>

Ah yes, the single quotes. When searching the forums I'd seen these in other replies but I hadn't realised their significance.

Many thanks for your response.

---

<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:23pm UTC](https://community.mp3tag.de/t/problem-with-sets-in-regexp/12078/4 "2026-02-09T12:23:08Z")

</div>


