Skip to content

Instantly share code, notes, and snippets.

@pedropolidoro
Last active November 11, 2021 01:57
Show Gist options
  • Save pedropolidoro/e9bac748c7970d91ecb688dd57506a92 to your computer and use it in GitHub Desktop.
Save pedropolidoro/e9bac748c7970d91ecb688dd57506a92 to your computer and use it in GitHub Desktop.
Regular expression for separate and recognize musical chords symbos when mixed with lyrics.
\b((?:[A-G]|vii|VII|vi|VI|v|V|iv|IV|iii|III|ii|II|i|I)[#b♯♭]?(?:m(?:i(?:n(?:or)?)?)?|\+|½?dim|º|°|⁰|◦|⸰|○|⚬|∆|Δ|△|Ø|ø|⌀|⊘|∅|au[gm]|alt|sus|dom|-|add|no|omit|[Mm]aj?|M|[#b♯♭+-]|\d+|\(|\)|\/)*(?:[A-G][#b♯♭]?)?(?:\(?drop\d\)?)?(?=\n|\s|$))
# This regular expression is for separate and recognize musical chords
# when mixed with lyrics.
# Start Limit
\b
(
# Fundamental
(?:[A-G]|vii|VII|vi|VI|v|V|iv|IV|iii|III|ii|II|i|I)[#b♯♭]?
# Term between fundamental and bass
(?:m(?:i(?:n(?:or)?)?)?|\+|½?dim|º|°|⁰|◦|⸰|○|⚬|∆|Δ|△|Ø|ø|⌀|⊘|∅|
au[gm]|alt|sus|dom|-|add|no|omit|[Mm]aj?|M|[#b♯♭+-]|\d+|\(|\)|\/)*
# Bass
(?:[A-G][#b♯♭]?)?
# Drop
(?:\(?drop\d\)?)?
# End Limite
(?=\n|\s|$)
)
@pedropolidoro
Copy link
Author

pedropolidoro commented Jul 26, 2021

This regular expression compared to the other file of other gist, is not strict, it allows strange combinations.

http://rubular.com/r/TU5Pjw9xzkUJYn

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment