Use a regular expression to get the image address in the article

Source: Internet
Author: User

Obtain the address of the first image from a text clip.

Refer to the various regular expressions on the Internet and finally debug them.

<%
'Str = "<a href =" "post. php? Action = newthread & amp; fid = 2 & amp; extra = page % 3D1 ""> </a> <br/> Str = "

Response. write (GetImgSrc (str ))

Function GetImgSrc (str) 'gets the img Tag content
Dim tmp
Set objRegExp = New Regexp
ObjRegExp. IgnoreCase = true' case insensitive
ObjRegExp. Global = false' full-text search! Key!
ObjRegExp. Pattern = "] *) (. *?)> "
Set Matches = objRegExp. Execute (str)
For Each Match in Matches
Tmp = tmp & Match. Value
Next
GetImgSrc = getimgs (tmp)
End function

Function getimgs (str )'
Set objRegExp1 = New Regexp
Objregexp1.ignorecase = true' case insensitive
Objregexp1.global = true' full-text search
Objregexp1.pattern = "src =. + [(GIF | JPG | PNG)] +" 'expression
Set Mm = objregexp1.execute (STR)
For each mattings in mm
Imgsrc = match1.value
'There may be characters that cannot be filtered. Make sure that
Imgsrc = Replace (imgsrc ,"""","")
Imgsrc = Replace (imgsrc, "src = ","")
Imgsrc = Replace (imgsrc, "<","")
Imgsrc = replace (imgsrc, "> ","")
Imgsrc = replace (imgsrc, "img ","")
Imgsrc = replace (imgsrc ,"","")
Getimgs = getimgs & imgsrc concatenate the addresses in the string for backup.
Next
End function
%>

Output:

Images/200610261533.jpg

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.