Obtain image addresses using ASP Regular Expressions

Source: Internet
Author: User

<%
Function regexp_execute (string)
Dim RegEx, match, matches, values.
Set RegEx = new Regexp 'to create a regular expression.
RegEx. pattern = "src \ =. +? \. (GIF | JPG) "'setting mode.
RegEx. ignorecase = true' specifies whether the characters are case sensitive.
RegEx. Global = true' to set global availability.
Set matches = RegEx. Execute (string) 'to perform the search.
For each match in matches 'traverses the matching set.
Values = Values & Match. Value & "" |"
Next
Regexp_execute = values
End Function
%>

Bytes --------------------------------------------------------------------------------------------------

<%
Dim result, result1
STR = "adfjlmnnzlkjlkfjoj dfkjhdjfk"
Set Re = new Regexp
Re. ignorecase = true
Re. Global = true
Re. pattern = "] * src =" "([^" ">] +)" "[^>] +>"
Set m1_re.exe cute (STR)
For each n in m
Result = Result & N &""
Result1 = result1 & N. submatches (0 )&""
Next
Set M = nothing
Set Re = nothing
If result <> "" then
Result = left (result, Len (result)-1)
Result1 = left (result1, Len (result1)-1)
End if
Result = Split (result, "") 'storage
Result1 = Split (result1, "") 'Stores image addresses
%>

Bytes --------------------------------------------------------------------------------------------------

<%

 

'Function: return a string, in which a specified number of substrings are replaced with another substring.
'Source: http://jorkin.reallydo.com/article.asp? Id = 406

Function replaceall (sexpression, Sfind, sreplacewith, ball)
If isnull (sexpression) Then replaceall = "": Exit Function
If cbool (ball) then
Do While instr (1, sexpression, Sfind, 1)> 0
Sexpression = Replace (sexpression, Sfind, sreplacewith, 1,-1, 1)
If instr (1, sreplacewith, Sfind, 1)> 0 Then exit do
Loop
Else
Do While instr (sexpression, Sfind)> 0
Sexpression = Replace (sexpression, Sfind, sreplacewith)
If instr (sreplacewith, Sfind)> 0 Then exit do
Loop
End if
Replaceall = sexpression
End Function

'Function: Get all image addresses and save them to an array.
'Need replaceall function: http://jorkin.reallydo.com/article.asp? Id = 406
Function getimg (sstring)
Dim sreallydo, RegEx, ireallydo
Dim omatches, cmatch
'// Defines an empty array
Ireallydo =-1
Redim areallydo (ireallydo)
If isnull (sstring) then
Getimg = ""
Exit Function
End if
'// Format the HTML code
'// Wrap each Sreallydo = sstring
On Error resume next
Sreallydo = Replace (sreallydo, vbcr ,"")
Sreallydo = Replace (sreallydo, vblf ,"")
Sreallydo = Replace (sreallydo, vbtab ,"")
Sreallydo = Replace (sreallydo, "Sreallydo = Replace (sreallydo, "/>", "/>", 1,-1, 1)
Sreallydo = replaceall (sreallydo, "=", "=", true)
Sreallydo = replaceall (sreallydo, ">", ">", true)
Sreallydo = Replace (sreallydo, "> <", ">" & vbcrlf & "<")
Sreallydo = trim (sreallydo)
On Error goto 0
Set RegEx = new Regexp
RegEx. ignorecase = true
RegEx. Global = true
'// Remove the onclick, onload, and other scripts
RegEx. pattern = "\ s [on]. +? = ([\ "" | \ ']) (. *?) \ 1"
Sreallydo = RegEx. Replace (sreallydo ,"")
'// Enclose the image address of SRC without quotation marks with quotation marks
RegEx. pattern = "] *). *?> "
Sreallydo = RegEx. Replace (sreallydo, " ")
'// The SRC address of the matching image
RegEx. pattern = " "
Set omatches = RegEx. Execute (sreallydo)
'// Save the image address to an array
For each cmatch in omatches
Ireallydo = ireallydo + 1
Redim preserve areallydo (ireallydo)
Areallydo (ireallydo) = RegEx. Replace (cmatch. value, "$2 ")
Next
Getimg = areallydo
End Function
%>

Related Article

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.