テキストから cdr (chordpro) へのコンバーターを作成していますが、フォームのコード ラインを検出するのに問題があります。
Cmaj7 F#m C7
Xxx xxxxxx xxx xxxxx xx x xxxxxxxxxxx xxx
これは私のpythonコードです:
def getChordMatches(line):
import re
notes = "[CDEFGAB]";
accidentals = "(#|##|b|bb)?";
chords = "(maj|min|m|sus|aug|dim)?";
additions = "[0-9]?"
return re.findall(notes + accidentals + chords + additions, line)
リスト ["Cmaj7", "F#m", "C7"] を返したい。上記のコードは機能しません。ドキュメントに苦労しましたが、どこにも行きません。
クラスとグループを連鎖させるだけではうまくいかないのはなぜですか?
編集
ありがとう、私は私のニーズのほとんどをカバーする次のものになりました(たとえば、E#m11とは一致しません)。
def getChordMatches(line):
import re
notes = "[ABCDEFG]";
accidentals = "(?:#|##|b|bb)?";
chords = "(?:maj|min|m|sus|aug|dim)?"
additions = "[0-9]?"
chordFormPattern = notes + accidentals + chords + additions
fullPattern = chordFormPattern + "(?:/%s)?\s" % (notes + accidentals)
matches = [x.replace(' ', '').replace('\n', '') for x in re.findall(fullPattern, line)]
positions = [x.start() for x in re.finditer(fullPattern, line)]
return matches, positions