re = /\b(?:G,C,D|A,B,C|E,C,D)|(?:[ABCDEFG](?:#|b)?)(?:\/[ABCDEFG]b)?(?:(?:(?:maj|min|sus|add|aug|dim)(?:\d{0,2}(?:#\d{1,2}|sus\d)?)?)|(?:m\d{0,2}(?:(?:maj|add|#)\d{0,2})?)|(?:-?\d{0,2}(?:\([^)]*\)|#\d{1,2})?))?/
str = '<p>Intro:G,C,D D, A, Em, Eb Ebb G G,C,D</p>
A,B,C <p><br />
Verse 1:</p> <p> D A Em <br />
Yeah I\'ve iced down a few thousand beers in my days<br />
G <br />
You put down twice as many<br /> D A Em <br />
C9 G C#/Db C# Dsus2sus4
Dmaj13#11
Bmaj13#11
A7(b5,#9)
A7#9
B-5
#sus #maj #min #aug'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html