<img  src="1.jpg" target=_blank>
<img width=80 height=90 src="2.jpg" title="查看图片" target=_blank>如何匹配图片地址

解决方案 »

  1.   

    我是想从src处着手匹配,因为情况有很多部,像http://***/***.jpg、x.gif,x.bmp什么之类的所在是一个图片链接地址的匹配
    ^\w+(\.[jpg]+)+$
    是不行的,不过谢谢
      

  2.   

    string imgHtml = Regex.Match("<html><img src='abc.html'></html>","<img ([0]|[^0])*?>",RegexOptions.IgnoreCase).Value;
    string src = Regex.Match(imgHtml,"src=([0]|[^0])*?( |>)",RegexOptions.IgnoreCase).Value;
    src = src.Replace("src=","").Replace("\"","").Replace("'","");
    src = src.Substring(0,src.Length-1);
      

  3.   

    Private Function GetPictureUrls(ByVal url As String) As ArrayList
            Dim html As String
            Dim pageAddress As Uri
            Dim match As Match
            Dim matches As MatchCollection
            Dim imgsrc, imgFullUrl As String
            Dim ext As String
            Dim pictures As New ArrayList        pageAddress = New Uri(url)
            html = GetHtml(url, "")
    matches = Regex.Matches(html, "<img.*?src\s*?=\s*[""|']?(?<imgsrc>[^""'>]*)[""|']?.*?>", RegexOptions.IgnoreCase)        For Each match In matches
                imgsrc = match.Result("${imgsrc}")
                ext = Path.GetExtension(imgsrc)
                If ext <> "" AndAlso txtImageTypes.Text.IndexOf(ext) > -1 Then
                    If imgsrc.ToLower().StartsWith("http://") Then
                        imgFullUrl = imgsrc
                    ElseIf imgsrc.StartsWith("/") Then
                        imgFullUrl = pageAddress.Host & imgsrc
                    Else
                        imgFullUrl = Path.GetDirectoryName(pageAddress.AbsolutePath) & "/" & imgsrc
                    End If                If Not pictures.Contains(imgFullUrl) AndAlso Not m_Pictures.Contains(imgFullUrl) Then
                        pictures.Add(imgFullUrl)
                        m_Pictures.Add(imgFullUrl)
                    End If
                End If
            Next        matches = Nothing
            pageAddress = Nothing        Return pictures
        End Function从我写的一个下载网页上所有图片的小程序上摘下来的,需要完整代码(2003项目)的留下email,本来想放在我的网站空间上的,可惜网站挂了