Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

how to distinguish a song liryc from a chord

Last post 07-17-2012, 10:17 AM by rodrigozem. 2 replies.
Sort Posts: Previous Next
  •  07-16-2012, 1:26 PM 85778

    how to distinguish a song liryc from a chord

    Regex:
    (?<=^|\s)[A-G](?:\x23|[2-9]|\x2F|maj|add|m(?!\s))?(?:\x2B|M|m|\[A-G]|\x28[2-9]\x29|[2-9])?(?:[2-9]|\x28[2-9]\x29)?(?:[2-9]|\x28[2-9]\x29)?(?=\s|$)

    I've used the regex above to match this song. The problem: it's matching part of the lyric on the last line; "Em" is a chord, but in portuguese can mean a word and it can not be matched.

    [INT] -> F#m B7(9) G#m7 , C#7(9)

    F#m7            B7(9)
    Quem quiser, poderá provar,
    F#m7             B7(9)
    E quem beber, sua sede vai matar,
    Bm(9) E  A7M D7(9)  G#m7 C#m7(9)   F#m7
    Da água da vida,      que Cristo    dá.
     Bm7    E           A7M
    Deus é paz, toda a guerra dissipou,
     Bm7    E            A7M
    Deus é vida, sobre a morte triunfou,
     Bm7   C#m7       D7M F#m7
    Em meu viver somos
    ...

    thanks!
    Filed under:
  •  07-16-2012, 9:49 PM 85785 in reply to 85778

    Re: how to distinguish a song liryc from a chord

    The problem is one of "context" for your regex pattern: the way you have written it is that it will find and match anything that looks like a chord reference anywhere in the text. What you will need to do is to think about what you need to do to determine when a match can be a chord reference and when it can't.

    For example, if the text you have provided is completely representative of all of the text you will ever encounter, then you might be able to detect which type of line you are scanning: it would seem that there are at least 2 chords on the "chord" line and only chords on that line; where as the lyric line *may* have something lthat looks like a chord but is unlikely to have every "word" on the line look like a chord.

    Therefore you could make 2 passes over the text: the first pass identifies the "chord" line and the the 2nd pass then splits just that line into the individual chords. Basically the patterns for both passes are exactly what you have now except the first pass one has a wrapper around it to require 2 or more matches. Therefore it might look something like:

    ^(\x20*
    [A-G] and the rest of your pattern up to (?=\s|$)
    ){2,}

    If you are using the .NET regex engine then you can actually use the "capture" level within each of the match groups to pick out the individual chords and do this in 1 pass. Otherwise, the above will match the "whole line" and you can use that as the text for your pattern to get the individual chords in the 2nd pass.

    Susan

  •  07-17-2012, 10:17 AM 85793 in reply to 85785

    Re: how to distinguish a song liryc from a chord

    Susan, thank you for your attention!!!
    First I used a expression matching the lines containing the chords and then separated each chord in another expression.

    result:
    >> First expression (I put it between <b> tag)

    (\r\n\s*(?:(?:\[.*?\])|(?:\(.*?\))|(?:INTRO|REFRÃO|VERSO|Verse|Introdução|>>||INT|BAIXO|TECLADO|GUITARRA|PRELÚDIO|INSTRUMENTAL|TAG|SOL|LA|OUTRO|SOLO|CORO|OUT|FINAL|INTERLÚDIO|[INT] ->|TOM|CHORUS|PONTE))?):?(?:\s+->)?([,\x00\xAA~;%*\x20\t#+\/\|\[\]>\d:A-GdimajPRSUuX\xB0\xBA()\.ph-]+)(?=\r\n|$)

    >> Second expression
    (?<=\s|<[bB]>)[A-G](?:\x23|\x23\xBA|[2-9]|[2-9]\x2F|\x2F|maj|b|add|m)?(?:\x2f|\x2B|M|m|[A-G]|\x281[1-3]\x29|\x28[2-9]\x29|[0-9])?(?:-|\+|[A-G]|\x23|\x281[1-3]\x29|[2-9]|\x28[2-9]\x29)?(?:\x23|\x2f|b|[2-9]|\x28[2-9]\x29)?(?:[2-9])?(?=\s|</[bB]>)
View as RSS news feed in XML