我将邮件内容(邮件正文)存储在数据库中。
我想从那些邮件内容中提取所有图像tag()的“src”属性值。
邮件正文中可能包含一个或多个图像。
请让我知道如何在VB.NET中达到此目的?
谢谢。
最佳答案
您可以使用正则表达式。
Try
Dim RegexObj As New Regex("<img[^>]+src=[""']([^""']+)[""']", RegexOptions.Singleline Or RegexOptions.IgnoreCase)
Dim MatchResults As Match = RegexObj.Match(SubjectString)
While MatchResults.Success
' SRC attribute is in MatchResults.Groups(1).Value
MatchResults = MatchResults.NextMatch()
End While
Catch ex As ArgumentException
'Syntax error in the regular expression (which there isn't)
End Try
运作方式如下:
<img[^>]+src=["']([^"']+)["']
Match the characters "<img" literally «<img»
Match any character that is not a ">" «[^>]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the characters "src=" literally «src=»
Match a single character present in the list ""'" «["']»
Match the regular expression below and capture its match into backreference number 1 «([^"']+)»
Match a single character NOT present in the list ""'" «[^"']+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a single character present in the list ""'" «["']»