Regex help required

Can I acheive the following?

John Smith => J Smith
Brian James Brown => B J Brown
John Smith, Brian James Brown => J Smith, B J Brown


Why do you want to throw away information that is usually very hard to get in the first place?
Better think twice.

You could create an action to format the tag, I assume it is the tag ARTIST?
The first construction is
$left(%artist%,1)$mid(%artist%,$strstr(%artist%," "),$len(%artist%))

The others then would use a construction that meanders about $mid(..,$add($str...),1),$strrchr(%artist%," ") $right(%artist%,$sub($len(%artist%,$strrchr(%artist%," ")

But I doubt that you will ever use it.

AND: you would have to very carefully have a look at the track you treat as otherwise groups like
Dave, Dee, Dozy, Beaky, Mick and Titch would become
D, D, D, B, M, a Titch

Mike and the Mechanics
M A T Mechanics...

Please enlighten me so I can see the point in this approach.

Thanks for the suggestion

I am keeping the full name (which is the composer name) but I need the short version of the names for the filename to keep the length of the filename down.

I am currently using a regexp which works for single first names only

(\w).?(\b\w)(,|$) => $1 $2$3

but not for double first names i.e.

John Smith, Brian James Brown => J Smith, B Brown

We are coming to a much more philosophical question: what is the purpose of a filename.
IMHO a filename is void - it only has to be unique.
Sometimes it is a good idea to cater for the limitations of a player that relies on filenames to get a sorting order. But in this case I would have to rename the files anyway.

Some people use filenames as extra data storage and as some kind of backup if the tags go wrong.
But if you wand to limit the length of a filename then the backup idea is pointless as you cannot use that information on a 1:1 basis - you would have to expand and re-edit the retrieved information anyway.
Of course, it may be an idea to prepare a restoring mechanism that stores the expanded information in actions to expand the compressed information that you retrieved from the filenames, e.g. replace J Smith with John Smith (although I know a Jaquelyn Smith also). But if you followed that approach then you could use it for compressing in the first place.
In a nutshell: I do not see any benefit in that kind of action particularly when it causes so much trouble to find the correct set of actions.

As an alternative: you could rename all your files with the converter tag-filename and truncate the generated filename to a certain length:

Enter the following mask:
$left("$num(%track%,3) - %artist% _ %album% _ %title%",40)
to cut the name after 40 characters.

$regexp(%artist%,(\w)\w*?(-| ),$1 )
or as you write it:
"(\w)\w*?(-| )" => "$1 " (without quotationmarks, just to show the space at the end)

This replacement shortens all words to one letter which are followed by " " or "-" (like John-Paul => J-P). You don't have to care about the last word in the regexp, if it is excluded by the match, it is kept unchanged.

You can leave the ARTIST field untouched if you want to format only the filename. Just use $regexp(%artist%,(\w)\w*?(-| ),$1 ) where you would have used %artist% before at formating the filename.
Like when you have the tag fields:
ARTIST = John Smith, Brian James Brown
TITLE = This Is Just A Song With A Very Long Title

Tag-Filename Converter:
Formatstring: $num(%track%,2) - $regexp(%artist%,(\w)\w*?(-| ),$1 ) - $left(%title%,20)

=> Filename = 01 - J Smith, B J Brown - This Is Just A Song W

But you can also cripple your ARTIST fields if you really want to:
Action: Format Value
Formatstring: $regexp(%artist%,(\w)\w*?(-| ),$1 )

Thanks guys. Too easy!

I had no idea you could use $regexp in the Format Value formatstring. I had only ever used Replace with Regular Expression before. Thanks for pointing that out Pone.