I have the following Regex to parse out a vCard: (VB)
Dim options As New RegexOptions()
options = RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.IgnorePatternWhitespace
regex = New Regex("(?<strElement>(N)) (;[^:]*)? (;CHARSET=UTF-8)? (:(?<strSurname>([^;\n\r]*))) (;(?<strGivenName>([^;\n\r]*)))? (;(?<strMidName>([^;\n\r]*)))? (;(?<strPrefix>([^;\n\r]*)))? (;(?<strSuffix>[^;\n\r]*))?", options)
m = regex.Match(s)
If m.Success Then
Surname = m.Groups("strSurname").Value
GivenName = m.Groups("strGivenName").Value
MiddleName = m.Groups("strMidName").Value
Prefix = m.Groups("strPrefix").Value
Suffix = m.Groups("strSuffix").Value
End If
It works when I have a vCard like:
BEGIN:VCARD
VERSION:2.1
N:Bacon;Kevin;Francis;Mr.;Jr.
FN: Mr. Kevin Francis Bacon Jr.
ORG:Movies.com
But it doesn't work correctly when the vCard is like this:
BEGIN:VCARD
VERSION:2.1
N:Bacon;Kevin
FN:Kevin Bacon
ORG:Movies.com
The regex assigns the <strSuffix> to Kevin, and not <strGivenName> like I wanted. How can I fix this?
Adapted regex came from here: vCard regex