Recommended: ASP tagged strings specify that they are case-insensitive The ordinary replacement function code is as follows: public function HighLight(S,F) dim tL,tM,tR,k tL= tM= tR=S k=instr(1,tR,F,1) do while k0 tL=tL left(tR,k-1) tM=mid(tR,k,len(F)) tL=tL span style='color:red' tM /span tR=right(tR,Len(tR)-len(F)-k+1) k=instr(1,tR,F,1) loop Hig
There are still bugs at present, and the latest test page is: http://www.reallydo.com/getimg.asp
The regular analysis page is at: http://jorkin.reallydo.com/article.asp?id=380
If you find a bug, please leave a message later, thank you.
1.31 Correction
src=The spaces after it cannot match correctly. Fixed.
An error occurred when src='' is empty. Fixed.
BUG was found: Only one can be retained when there are multiple spaces in the image path. Uncorrected.
2.18 Correction
When the image path has multiple spaces, only one bug can be retained. Fixed.
<%
'Function: Get all image addresses and save them to an array.
'Source: http://jorkin.reallydo.com/article.asp?id=448
'ReplaceAll function is required: http://jorkin.reallydo.com/article.asp?id=406
Function getIMG(sString)
Dim sReallyDo, regEx, iReallyDo
Dim oMatches, cMatch
'//Define an empty array
iReallyDo = -1
ReDim aReallyDo(iReallyDo)
If IsNull(sString) Then
getIMG = aReallyDo
Exit Function
End If
'//Format HTML code
'//Bring each <img line break to facilitate regular replacement
sReallyDo = sString
On Error Resume Next
sReallyDo = Replace(sReallyDo, vbCr, )
sReallyDo = Replace(sReallyDo, vbLf, )
sReallyDo = Replace(sReallyDo, vbTab, )
sReallyDo = Replace(sReallyDo, <img , vbCrLf & <img , 1, -1, 1)
sReallyDo = Replace(sReallyDo, />, />, 1, -1, 1)
sReallyDo = ReplaceAll(sReallyDo, = , =, True)
sReallyDo = ReplaceAll(sReallyDo, > , >, True)
sReallyDo = Replace(sReallyDo, ><, > & vbCrLf & <)
sReallyDo = Trim(sReallyDo)
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
'//Remove onclick, onload and other scripts
regEx.Pattern = /s[on].+?=([/|/'])(.*?)/1
sReallyDo = regEx.Replace(sReallyDo, )
'//Put the SRC image address without quotes
regEx.Pattern = <img.*?/ssrc=([^//'/s][^//'/s>]*).*?>
sReallyDo = regEx.Replace(sReallyDo, <img src=$1 />)
'//Regularly match the image SRC address
http://bizhi.cncms.com/
regEx.Pattern = <img.*?/ssrc=([//'])([^//']+?)/1.*?>
Set oMatches = regEx.Execute(sReallyDo)
'//Save the image address into the 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
%>
<%
'Usage: Many people ask me how to use it, but in fact, how to use the array.
sContent = HTML code field'//sContent represents Html code. It turns out that if you write ors, why don't you understand that it is a record set? . .
Dim aImages : aImages = GetImg(sContent) '//Define an array and use it to store all analyzed image addresses
'List the addresses of all pictures:
For i = 0 To UBound(aImages)
Response.Write(<b>Things & i + 1 & Image Address:</b> & aImages(i) & <br />)
Next
'List the first image address:
If UBound(aImages)> -1 Then Response.Write(<p><b>First image address:</b> & aImages(0) & </p>)
'List the last image address:
If UBound(aImages)> -1 Then Response.Write(<p><b>Last image address:</b> & aImages(UBound(aImages)) & </p>)
%>
Share: How to replace Replace in ASP in case insensitive Let's first look at the detailed parameter description of Replace Return string, where a specified number of substrings is replaced with another substring. Syntax Replace(expression, find, replace with[, compare[, count[, start]]]]) The syntax of the Replace function has the following parameters: Parameter description expression Required. String expression package