RegExp to extract text before first comma

I use MP3TAG to set the metadata and file name for my audiobooks. For the file name, I like as much info about the book without making it too long. It is in the format

Author -- Title (Narrator) (Chapter/track).mp3 <- Narrator is stored in %composer%

I had an issue in that some books have multiple narrators (e.g., Frank Mueller, David Cummings, Andrea Martin) and I didn't want the file name to be too long, so I just wanted the first narrator in the list from the metadata. So, I use that TAG -> FILENAME tool and include a REGEXP expression to pull only the first narrator, as follows:

%artist% -- %title% ($regexp(%composer%,^(.+?)\x{002c}(.*),$1)) (Ch%track%)

The REGEXP portion [$regexp(x,e,r,c)] is this

$regexp(%composer%,^(.+?)\x{002c}(.*),$1)

where

$regexp( string function to start regular expression
%composer% x entry, initial string where the narrators are stored
^(.+?)\x{002c}(.*) e entry, the regular expression
^ start at beginning of string
(.+?) extract any character non-greedy → this goes into $1
\{002c} up to first comma (comma must be escaped or Unicode) -> not stored
(.*) extract everything else → this goes into $2
$1 r entry, The field to be displayed

Hope this helps others.

1 Like

This is not quite true if you use
$regexp(%composer%,'^(.+?),.*',$1)
instead
The potential section following the comma does not necessarily need the parenthesis if you do not want to use it anyway, so $2 is not mandatory.
... but there are so many ways to solve the problem.