Use regular expressions to implement pattern Picture News (enhanced). Asp

Source: Internet
Author: User
Tags chr implement regular expression
Regular customer requirements to save the original IMG already in the attribute, depressed, continue to change

The code is as follows:


function Shownew (content,ntype)

Shownew = ""

if (ntype = 1) Then

Shownew = shownew & "<table width=100% >"
Shownew = shownew & "<TR>"
Shownew = shownew & "<td width=700 align=center style= ' word-break:break-all ' valign=top>" &ShowPic ( Content) & "</TD>"
Shownew = shownew & "</TR>"
Shownew = shownew & "<TR>"
Shownew = shownew & "<td valign=top style= ' Word-break:break-all ' >" &onlyword (Content) & "</TD>"
Shownew = shownew & "</TR>"
Shownew = shownew & "</TABLE>"


ElseIf (ntype = 2) Then


Shownew = shownew & "<table width= ' 100% ' >"

Shownew = shownew & "<TR>"
Shownew = shownew & "<td style= ' Word-break:break-all ' valign=top>" &onlyword (content) & "</TD>"
Shownew = shownew & "</TR>"
Shownew = shownew & "<TR>"
Shownew = shownew & "<td align=center width=700 valign=top style= ' Word-break:break-all ' >" &ShowPic ( Content) & "</TD>"
Shownew = shownew & "</TR>"
Shownew = shownew & "</TABLE>"

ElseIf (ntype = 3) Then


Shownew = shownew & "<TABLE>"

Shownew = shownew & "<TR>"
Shownew = shownew & "<td width=100 align=center valign=top>" &showpic (content) & "</TD>"

Shownew = shownew & "<td width=80% style= ' word-break:break-all ' valign=top>" &onlyword (content) & " </TD> "


Shownew = shownew & "</TR>"
Shownew = shownew & "</TABLE>"

ElseIf (ntype = 4) Then

Shownew = shownew & "<TABLE>"

Shownew = shownew & "<TR>"

Shownew = shownew & "<td width=80% valign=top style= ' Word-break:break-all ' >" &onlyword (Content) & " </TD> "
Shownew = shownew & "<td width=100 valign=top align=center>" &showpic (content) & "</TD>"

Shownew = shownew & "</TR>"
Shownew = shownew & "</TABLE>"
Else
Shownew = Shownew &content
End If

End Function

' Show the extracted picture
function Showpic (STRNG)

Set regEx2 = new REGEXP

Regex2.pattern = "(src=) (' |") &AMP;CHR (&) | )? (. [^'| |" &AMP;CHR (& "]*)" (\.) (Jpg|gif|png|bmp|jpeg) ('|" &AMP;CHR (& "| |>)"? ' Set mode.
Regex2.ignorecase = True ' Sets whether character case is case-sensitive.
Regex2.global = True ' Sets global availability.

Showpic = ""
Imageurl= Regexpexecute (STRNG)

Imageurls = Split (ImageUrl, "{| ldiv|} ")


For i = LBound (Imageurls) to (UBound (imageurls)-1)


Set Matches2 = Regex2.execute (Imageurls (i)) ' performs a search.


For each Match2 in Matches2 ' Traversal matching collection.

' Full img tag
Newpic = LCase (Imageurls (i))

' If no custom border add border=0, other original attributes remain

if (InStr (Newpic, "border") =false) then Newpic = Left (Newpic,len (newpic)-1) + "border= ' 0 ' >"
if (InStr (Newpic, "width") =false) then Newpic = Left (Newpic,len (newpic)-1) + "width= ' >"

Newpic = "<a style= ' padding:20px ' href= '" &match2.submatches (2) &match2.submatches (3) & Match2.submatches (4) & "' >" & newpic & "</a>"

Showpic = showpic & Newpic
Next


Next

Set regEx2 = Nothing
End Function


' Extract the picture from the content
Function Regexpexecute (STRNG)
Dim regEx, Match, matches ' Set variable.
Set regEx = New RegExp ' establishes a regular expression.

Regex.pattern = "(<) (. [ ^<]*) (src=) (' | ') &AMP;CHR (&) | )? (. [^ ' |\s| ' &AMP;CHR (& "]*)" (\.) (Jpg|gif|png|bmp|jpeg) ('|" &AMP;CHR (& "|\s|>") (. [ ^>]*) (>) "' Set mode.


Regex.ignorecase = True ' Sets whether character case is case-sensitive.
Regex.global = True ' Sets global availability.
Set matches = Regex.execute (strng) ' performs a search.
For the match in matches ' traversal matching collection.
Values=values&match.val



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.