tags:

views:

634

answers:

2

Hi folks

I am making a mp3 id3tag editor, and a regex is not matching. Could anyone help me please? my code:

arquivo = "[coletanea] album [CD #] [faixa] [artista] musica.mp3"

r = New Regex("^\[(?<1>[^\]]+?)\]\s*(?<2>[\w\s]+)\s*\[CD\s*(?<3>\d+)\]\s*\[(?<4>\d+)\]\s*\[(?<5>[^\]]+)\]\s*(?<6>.+)", RegexOptions.Compiled)
m = r.Match(Mid(arquivo, 1, Len(arquivo) - 4))
        If m.Success Then
            mAuthor = Trim(m.Groups(5).ToString)
            mWM_AlbumTitle = Trim(m.Groups(2).ToString)
            mWM_TrackNumber = Trim(m.Groups(4).ToString)
            mTitle = Trim(m.Groups(6).ToString)
            mWM_PartOfSet = Trim(m.Groups(3).ToString)
            mMW_AlbumArtist = Trim(m.Groups(1).ToString)
        End If

thx

+3  A: 

That's because your string will never match the regexp you are using.

The regexp expects a number instead of # and a number instead of 'faixa'

Try this, for example:

"[coletanea] album [CD 20] [89] [artista] musica.mp3"

If you wish to allow for any character instead of just numbers, replace \d for . in the groups 3 and 4

Vinko Vrsalovic
+1  A: 

Well, your string dosen't match the regexp (since '#' and 'faixa' is not digits) try with this string witch I'm guessing is the string you will get from the system:

"[coletanea] album [CD 1] [1] [artista] musica.mp3"

Its also a little weird to name the capture groups to numbers like this, because the groups will be named starting at 0 by default.

Tjofras