Python Regex to detect musical chords? (modified) -


I am working on a wire transposer in Python, and I'm mostly working, but some problems with my Reggae And I was thinking that if someone is more intelligent in reggax methods then there can be an idea of ​​fixing me. I am essentially using this regex, found in another thread:

  import ref def (line): notes = "[CDEFGAB]"; Accidental = "(?: ### | B | Bb)?"; Chords = "(?: Maj | min | m | sus | aug | dim)?"; Extra = "[0- 9]?" # A1, which works: Line = "AA7 AM 7 BM CMA 7" Print SearchCode (line) ['A', 'A7', 'M7', 'BB', 'CMJ 7'] # Case 2, who thinks the capital C is a string in the chorus. Line = "chorus: a7 am 7 bb cmaz 7" print searchcard (line) ['c', 'a', 'a7', 'm7', 'bb', 'cmaj 7']   P> As you can see, "Case 1" above works just fine. However, "case 2" fails, the word "chorus" has a wire considering the capital C.  

Can anyone think of a way to modify the "notes" portion of Regedek, which is smart enough to make such a mistake? This should also leave things like "B" in "baseball" etc.

Thanks for any help.

to start regex r '\ b' and finally Add r '(?! \ W!)' , by creating it so that regex can only be against something that is a complete word (where "word" is the sequence of alphanumeric characters and / or underscores Is):

  def findChords (line): notes = "[CDEFGAB]"; Accidental = "(?: ### | B | Bb)?"; Chords = "(?: Maj | min | m | sus | aug | dim)?"; Extra = "[0- 9]?" Return Refunds (RB + + + Notes + Accidentally + Cord + Adwords + R '(?! \ W)', line)   

(Note that we can not use R '\ b' Finally because a string ending with # will never be accepted.)

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -