mardi 3 mars 2015

Extract variables from pattern matching

I'm not a match-pattern expert and I've been working on this for a few hours with no chance :/


I have an input string just like this:



Dim text As String = "32 Barcelona {GM C} 2 {*** Some ""cool"" text here}"


And I just want to extract 3 things:



  1. Barcelona

  2. GM C

  3. *** Some "cool" text here


The pattern I'm trying is something like this:



Dim pattern As String = "^32\s(?<city>[^]].*\s)\{(?<titles>.*\})*"

Dim m As Match = Regex.Match(text, pattern)

If (m.Success) Then

Dim group1 As Group = m.Groups.Item("city")
Dim group2 As Group = m.Groups.Item("titles")

If group1.Success Then
MsgBox("City:" + group1.Value + ":", MsgBoxStyle.Information)
End If

If group2.Success Then
MsgBox(group2.Value, MsgBoxStyle.Information)
End If

Else
MsgBox("fail")
End If


But it's not working anyway :( What should the pattern be to extract these 3 variables ?


Aucun commentaire:

Enregistrer un commentaire