Extract Artist And Title From A Song Title String
Join the DZone community and get the full member experience.Join For Free
Extract the artist and the title of the song from a string formatted as: ARTIST - TITLE.EXT This code strips the extension, splits the string, trims each part and capitalize it correctly (fixed pythons string.title() bug for handling apostrophes)
#filename = "rihanna - please don't stop the music.pdf" artist, title = [re.sub("([a-zA-Z])'([A-Z])", lambda m: m.group(1) + "'" + m.group(2).lower(), t.strip().title()) for t in filename[:filename.rfind('.')].split('-')]
Strings Extract Data Types
Opinions expressed by DZone contributors are their own.