我有一個我試圖解析以下文本電子郵件地址和用戶名:我怎麼能組多使用正則表達式
"[email protected]" <[email protected]>, "Jane Doe" <[email protected] addyB.org>, "[email protected]" <[email protected]>
我使用下面的代碼,試圖分裂的字符串:
Dim groups As GroupCollection
Dim matches As MatchCollection
Dim regexp1 As New Regex("""(.*)"" <(.*)>")
matches = regexp1 .Matches(toNode.InnerText)
For Each match As Match In matches
groups = match.Groups
message.CompanyName = groups(1).Value
message.CompanyEmail = groups(2).Value
Next
但這正則表達式是貪婪和之後「[email protected]」被抓住了整個字符串到最後的報價。我很難拼湊一個表達式,將該字符串分組到我要查找的兩個組中:名稱(在引號中)和電子郵件(在尖括號中)。有人有任何意見或建議,以改變正則表達式來獲得我所需要的?
第一部分應該是``「([^」「] *)」「`,而不是`」「([^)] *)」「``。 – 2009-08-04 15:48:32
當然可以。我把所有的標點符號都弄糊塗了;-) – sepp2k 2009-08-04 16:21:25