# RegEx Help

**URL:** https://community.mp3tag.de/t/regex-help/11672
**Category:** General Discussion
**Created:** [March 5, 2011, 9:56pm UTC](https://community.mp3tag.de/t/regex-help/11672 "2011-03-05T21:56:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![emalvick](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@emalvick](https://community.mp3tag.de/u/emalvick)
#### Post date: [March 5, 2011, 9:56pm UTC](https://community.mp3tag.de/t/regex-help/11672/1 "2011-03-05T21:56:54Z")

</div>

This is going to be a simple question, but for some reason I am stuck in getting the result I want.

I am formatting file names, and I am wanting to make use of my %artist% field but not the whole thing...

For instance, If I have a track that is a duet:

%artist% = U2/B.B. King

I want to grab something before the / and put that into the file name.

I tried using something like $regexp(%artist%,(\w\*?)/.+,$1)

This is not working, and for some reason I am not seeing how I should be doing it. I am especially concerned about cases where there may not be 2 artists (i.e. no / character) and also cases where there are going to be spaces, periods, etc.

Maybe I am looking for something too complicated.

If anyone has any suggestions or even a start, I'll appreciate it.

Thank you,

Erik

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [March 5, 2011, 11:08pm UTC](https://community.mp3tag.de/t/regex-help/11672/2 "2011-03-05T23:08:29Z")

</div>

> [@Erik Malvick](#):
>
> %artist% = U2/B.B. King
> 
> I want to grab something before the / and put that into the file name.
> 
> I tried using something like $regexp(%artist%,(\w\*?)/.+,$1)
> 
> This is not working, and for some reason I am not seeing how I should be doing it. I am especially concerned about cases where there may not be 2 artists (i.e. no / character) and also cases where there are going to be spaces, periods, etc.

**$regexp(%artist%,(.\*?) \*/.+,$1)**

**.+** was the reason why your string did not work. use only **.+**  
use **(._?)_** _instead of **(\w**_**?)** because **\w** doesn't work when the the artist name has spaces, periods, etc  
insert " **\***" before " **/**" so you don't have a space at the end if " **/**" is written like " **/**"  
if there is only one artist without **/** character, the regular expression is not found and **%artist%** is written without replacement, i.e. left unchanged.

---

<div class="post-metadata">

### Author: ![emalvick](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@emalvick](https://community.mp3tag.de/u/emalvick)
#### Post date: [March 5, 2011, 11:55pm UTC](https://community.mp3tag.de/t/regex-help/11672/3 "2011-03-05T23:55:45Z")

</div>

> [@pone](#):
>
> **$regexp(%artist%,(.\*?) \*/.+,$1)**
> 
> **.+** was the reason why your string did not work. use only **.+**  
> use **(._?)_** _instead of **(\w**_**?)** because **\w** doesn't work when the the artist name has spaces, periods, etc  
> insert " **\***" before " **/**" so you don't have a space at the end if " **/**" is written like " **/**"  
> if there is only one artist without **/** character, the regular expression is not found and **%artist%** is written without replacement, i.e. left unchanged.

Fantastic.

I appreciate the code and the explanation. I never use the regular expressions often enough to remember some of these details. They are so handy when I do need them.
