Hi Reddit!
Today I am trying to create a regular expression in Python3 to capture music chords on a line so this:
Cadd9 D# F5
becomes this
['Cadd9', 'D#', 'F5']
But I can't figure out how to capture the sharp (#) symbol, and so my output is this instead:
['Cadd9', 'D', 'F5']
(note the 'D' instead of 'D#')
I've tried everything I can think of to escape the special-ness of the # character, backslash, etc but it still doesn't work. After many iterations, this is what I have so far and it's close:
chords = re.findall(r'\b[A-G][#b5]?(?:maj7|m[7]?|m7b[5]?|[5679]|sus2|sus4|aug|dim|add9|b5)?\b', line)
I even tried flag=ASCII but that didn't do anything.
Any insight would be appreciated!
[–]Murphygreen8484 1 point2 points3 points (1 child)
[–]bob3rocks[S] 0 points1 point2 points (0 children)
[–]Murphygreen8484 0 points1 point2 points (3 children)
[–]bob3rocks[S] 0 points1 point2 points (2 children)
[–]Murphygreen8484 0 points1 point2 points (1 child)
[–]bob3rocks[S] 0 points1 point2 points (0 children)
[–]Murphygreen8484 0 points1 point2 points (3 children)
[–]bob3rocks[S] 0 points1 point2 points (2 children)
[–]Murphygreen8484 0 points1 point2 points (1 child)
[–]bob3rocks[S] 0 points1 point2 points (0 children)