Let's say I have some music files organized (poorly) by artist name, for example:
/data/myfolder/Jay Z/some_file1.mp3
/data/myfolder/Jay-Z/some_file2.mp3
/data/myfolder/JayZ/some_file3.mp3
/data/myfolder/Destiny's Child/some_file4.mp3
/data/myfolder/Destinys Child/some_file5.mp3
I want to run some batch operations using regex matching. However, I want to ignore the special characters within the artist's names when finding my matches. I could programmatically replace special characters with python, but I'm wondering if its possible to do it completely with the regex pattern.
For example, the following code would only work on some_file1.mp3 and some_file4.mp3 as it is currently written:
import os
import re
artists = ["Jay Z", "Destiny's Child"]
root = "/data/myfolder/"
for filepath in os.listdir(root):
for artist in artists:
pattern = r"\/data\/myfolder\/{}\/.*.mp3".format(artist)
match = re.search(pattern, filepath)
if match:
...do some stuff...
Is there some way to modify my regex pattern from /\/data\/myfolder\/{}\/.*.mp3.format(artist) so that it would successfully match even when there is a dash, single quote, or other specified special character within the string? Basically, I'm trying to ignore the presence of certain characters anywhere in a string when looking for a match.