RegEx Help


#1

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


#2

$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.


#3

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.