This Python regex allows you to split an audio filename with the sintax Authors - Title (Text1) [Text2].extension
into:
Authors
Title
Text1
Text2
.extension
It is oriented to use .fullmatch()
since the objective is to guarantee the capture of lastest groups.
Moreover, it handles copies of the files thanks to the latest non-capturing group (?:\s*-*[\w*\s*]*)?
. See the last example.I.e., for the following filenames:
Author - Title.extension
Author
Title
.extension
Author1&Author2-This is a title(feat. Someone)[NoPremiere].mp3
Author1&Author2
This is a title
feat. Someone
NoPremiere
.mp3
Author1 & Author2 - Title with & (This) (Is) [Too] [Spaced] .m4u
Author1 & Author2
Title with &
Is
Spaced
.m4u
name1 - title1 ( album1 ) - copy.mp3
name1
title1
album1
.extension
Note: this regex will only get the latest string in the parentheses and in the square brackets and won't match more of them. In order to obtain all inside them, re.findall() should be implemented. Also, non-word and non-whitespace characters are not supported after the last hyphen.