Forum UBB Code Recommendation _ Regular Expression

Source: Internet
Author: User
Tags chr

Copy Code code as follows:

<%
Dim Param,smiles ' Param is a fully available tag for UBB tags param=full is fully available, otherwise it does not support some placeholder labels smiles is no smiley-face conversion
function Ubbcode (content)
Dim n,i
' On Error Resume Next
Set Re=new regexp
Re. Ignorecase=true
Re.global=true

Re.pattern= "\[code\]" (\ r \ n)? ([\s\s]+?) \[\/code\] "
Set matches = Re. Execute (content)
Dim code ()
N=0
If Re.test (content) then Codeb=true
If Codeb Then
For the Match in matches
ReDim Preserve Code (N)
Code (N) =match.value
N=n+1
Next
For i=0 to UBound (code)
If code (i) = "" Then Exit for
Content=replace (Content,code (i), "{Code" &i& "}")
Next
End If

if param= "full" then
re.pattern= "\[html\" (\ r \ n)? ( [\s\s]+?] \[\/html\] "
Set matches = Re. Execute (content)
Dim html ()
N=0
If re.test (content) then Htmlb=true
If htmlb then
  for Match In matches
   ReDim Preserve HTML (n)
    HTML (n) =match.value
n=n+1
  Next
for i=0 to UBound (HTML)
if HTML (i) = "" Then Exit for
Content=replace (content,html (i), "{HTML" &i& "}")
Next
End If
End If
content=gmt (content)     ' Ubb


If Codeb then
for i=0 to UBound (code)
if code (i) = "" Then Exit for
Tcode=server.htmlencode (Code (i))
Content=replace (Content, "{Code" &i& "}", Tcode)
Next
End If
'-----process [HTML]
in [code] re.pattern= "\[html\]" (\ r \ n)? ([\s\s]+?) \[\/html\] "
Set matches = Re. Execute (content)    ' Execute search.
Dim html2 ()
N=0
If re.test (content) then Html2b=true
If Html2b then
  for all Match in matches  ;     ' iterate matches collection.
   ReDim Preserve HTML2 (N)
    html2 (n) =match.value
n=n+1
  Next
for I =0 to UBound (HTML2)
If HTML2 (i) = "" Then Exit for
Content=replace (CONTENT,HTML2 (i), "{HTML2" &i& "}")
Next
End If

If param= "full" then
If HTMLB Then
For i=0 to UBound (HTML)
If HTML (i) = "" Then Exit for
Thtml=server.htmlencode (HTML (i))
Content=replace (Content, "{html" &i& "}", thtml)
Next
End If
End If

Re. Pattern= "(\[code\]) (\ r \ n)? ([\s\s]+?) (\[\/code\]) "
Content=re. Replace (Content, "<pre class=codesamp>$3</pre>")

If param= "full" then
Re. Pattern= "(\[html\]) (\ r \ n)? ([\s\s]+?) (\[\/html\]) "
Content=re. Replace (Content, "<span><textarea cols=95 rows=12>$3</textarea><br><input onclick= RunCode () Type=button value= Run code > <input onclick=copycode () Type=button value= Copy code >[ctrl+a All selection tips: You can modify some of the code first, Then press run]</span> ")
End If

If Html2b Then
For i=0 to UBound (HTML2)
If HTML2 (i) = "" Then Exit for
THTML2=HTML2 (i)
Content=replace (Content, "{HTML2" &i& "}", THTML2)
Next
End If

Ubbcode=content
End Function


function GMT (strcontent)

Strcontent=htmlfilter (strcontent)

Dim re
Set re=new REGEXP
Re. IgnoreCase =true
Re. Global=true


If param= "full" then
If not smiles then ' smiley face conversion

Re. Pattern= "(\[em (\d{1,2}) \])"
Strcontent=re. Replace (strcontent, "

' Re. pattern= ": \)"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ": \ ("
' Strcontent=re. Replace (strcontent, "' Re. pattern= ": o"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ":D"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= "; \)"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ":p"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ": Cool:"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ": rolleyes:"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ": Mad:"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ": Eek:"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ": Confused:"
' Strcontent=re. Replace (strcontent, "' Re. Pattern= ": Cry:"
' Strcontent=re. Replace (strcontent, "

End If

Re. Pattern= "(\[img\]) (. *?) (\[\/img\]) "
Strcontent=re. Replace (strcontent, "<a href=$2 target=_blank>document.body.clientwidth-300) {this.height= (document.body.clientwidth-300) *this.height/this.width;this.width=document.body.clientwidth-300} " "Galleryimg=no></a>")

' Re. Pattern= "\[dir=* ([0-9]*), * ([0-9]*) \] (. *?) \[\/dir] "
' Strcontent=re. Replace (strcontent, "<object classid=clsid:166b1bca-3f9c-11cf-8075-444553540000 codebase=http:// download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=$1 Height=$2><param name= SRC value=$3><embed src=$3 pluginspage=http://www.macromedia.com/shockwave/download/width=$1 height=$2> </embed></object> ")
' Re. Pattern= "\[qt=* ([0-9]*), * ([0-9]*) \] (. *?) \[\/QT] "
' Strcontent=re. Replace (strcontent, "<embed src=$3 width=$1 height=$2 autoplay=true loop=false controller=true playeveryframe=false Cache=false scale=tofit bgcolor= #000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/ Quicktime/> ")
Re. Pattern= "\[mp= (\d+), (\d+) \] (. *?) \[\/MP] "
Strcontent=re. Replace (strcontent, "<object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 Class=OBJECT id= MediaPlayer width=$1 height=$2 ><param name=showstatusbar value=-1><param name=playcount value=10>< param name=filename value= "" $ "" ><embed type=application/x-oleobject codebase=http://activex.microsoft.com/ activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src= "" $ "" playcount=10 width=$1 height=$2 ></embed></object> ")

        ' mp3
       re. Pattern= "\[mp3]" (. *?) \[\/mp3] "
 strcontent=re. Replace (strcontent, "<object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 Class=OBJECT id= MediaPlayer width=300 height=180 ><param name=showstatusbar value=-1><param name=playcount value=10> <param name=filename value= "" $ "><embed type=application/x-oleobject codebase=http:// activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src= "" $ "playCount =10 width=300 height=180></embed></object> ")


Re. Pattern= "\[rm= (\d+), (\d+) \] (. *?) \[\/RM] "
Strcontent=re. Replace (strcontent, "<object CLASSID=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA class=object Id=RAOCX width=$1 Height=$2><param name=src value= "" $ "" ><param name=console value=clip1><param NAME=CONTROLS VALUE= Imagewindow><param Name=autostart value=true></object><br><object Classid=CLSID: CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1><param NAME=SRC VALUE= "" $ "><PARAM Name=autostart value=-1><param name=controls Value=controlpanel><param NAME=CONSOLE VALUE=Clip1>< /object> ")

Re. Pattern= "(\[flash\]) (. *?) (\[\/flash\]) "
Strcontent= Re. Replace (strcontent, "<object codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab# version=6,0,29,0 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 width=500 Height=400><PARAM NAME=movie Value= "" $ "" ><param name=quality value=high><embed src= "" $ "" Quality=high pluginspage= "http:// Www.macromedia.com/go/getflashplayer ' type= ' Application/x-shockwave-flash ' width=500 height=400>$2</embed ></OBJECT> ")
Re. Pattern= "(\[flash= (\d+), (\d+) \]) (. *?) (\[\/flash\]) "
Strcontent= Re. Replace (strcontent, "<object codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab# version=6,0,29,0 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 width=$2 Height=$3><param NAME=movie Value= "" $ "" ><param name=quality value=high><param name=menu value=false><embed src= "" $ "" Quality =high menu=false pluginspage= ' http://www.macromedia.com/go/getflashplayer ' type= ' Application/x-shockwave-flash ' Width=$2 height=$3>$4</embed></object> ")


' Cyclic conversion quote
Re. Pattern= "(\[quote\]) (. *?) (\[\/quote\]) "
While Re.test (strcontent)
Strcontent=re. Replace (strcontent, "<blockquote> reference: Wend

Re. Pattern= "(\[w\]) (. *?) (\[\/w\]) "
Strcontent=re. Replace (strcontent, "<iframe frameborder=1 align=center width=100% height=400 scrolling=yes SRC=$2></iframe ><br> page: <a href=$2 target=_blank> dot here visit </A> ")

End If ' Large space label

Re. Pattern= "(\[attachment= (. *?) \])(.*?) (\[\/attachment\]) "
Strcontent= Re. Replace (strcontent, "<p> <a href=" "$" "Target=_blank title=" "Hint:" &CHR & "You can click the right mouse button to save the file to the local machine" ">$3</a><p>"

Re. Pattern= "(\[url\]) (. *?) (\[\/url\]) "
Strcontent= Re. Replace (strcontent, "<a href=" "$" "target=_blank>$2</a>")
Re. Pattern= "(\[url= (Http|https|ftp|rtsp|mms) (: \/\/) (. *?) \])(.*?) (\[\/url\]) "
Strcontent= Re. Replace (strcontent, "<a href=" "$2$3$4" "target=_blank>$5</a>")

Re. Pattern= "(\[email\]) (. *?) (\[\/email\]) "
Strcontent= Re. Replace (strcontent, "<a href=" "mailto:$2" ">$2</A>")
Re. Pattern= "(\[email= (. *?) \])(.*?) (\[\/email\]) "
Strcontent= Re. Replace (strcontent, "<a href=" "mailto:$2" "target=_blank>$3</a>")

Re. Pattern = "(^|\s|<br>|<p>) (Http|https|ftp|rtsp|mms) (: \/\/) (\s+)"
Strcontent = Re. Replace (strcontent, "$1<a target=_blank href=$2$3$4>$4</a>")
Re. Pattern = "(^|\s|<br>|<p>) (www.) (\s+) "
Strcontent = Re. Replace (strcontent, "$1<a target=_blank href=http://$2$3>$2$3</a>")

' Text effect
Re. Pattern= "(\[list\]) (. +?) (\[\/list\]) "
Strcontent=re. Replace (strcontent, "<ul type=square>$2</ul>")
Re. Pattern= "(\[list=) (a|1) (\]) (. +?) (\[\/list\]) "
Strcontent=re. Replace (strcontent, "<ol type=$2>$4</ol>")
Re. Pattern= "(\[\*\])"
Strcontent=re. Replace (strcontent, "<LI>")

Re. Pattern= "(\[color= (. *?) \])(.*?) (\[\/color\]) "
Strcontent=re. Replace (strcontent, "<font color=$2>$3</font>")
Re. Pattern= "(\[# (. { 6}?) \])(.*?) (\[\/#\])"
Strcontent=re. Replace (strcontent, "<font color=#$2>$3</font>")
Re. Pattern= "(\[font= (. *?) \])(.*?) (\[\/font\]) "
Strcontent=re. Replace (strcontent, "<font face=$2>$3</font>")
Re. Pattern= "(\[align= (left|center|right) \]) (. *?) (\[\/align\]) "
Strcontent=re. Replace (strcontent, "<div align=$2>$3</div>")

 re. Pattern= "(\[fly\]) (. *?) (\[\/fly\]) "
 strcontent=re. Replace (strcontent, "<marquee width=90% behavior=alternate scrollamount=3>$2</marquee>")
 re. Pattern= "(\[move\]) (. *?) (\[\/move\]) "
 strcontent=re. Replace (strcontent, "<marquee scrollamount=3>$2</marquee>")  
 re. Pattern= "\[glow=* ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*) \] (. *?) \[\/glow] "
 strcontent=re. Replace (strcontent, "<table width=$1 style=" "Filter:glow (color=$2, strength=$3)" ">$4</table>")
 re. Pattern= "\[shadow=* ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*) \] (. *?) \[\/shadow] "
 strcontent=re. Replace (strcontent, "<table width=$1 style=" "Filter:shadow (color=$2, strength=$3)" ">$4</table>")

Re. Pattern= "(\[i\]) (. *?) (\[\/i\]) "
Strcontent=re. Replace (strcontent, "<i>$2</i>")
Re. Pattern= "(\[u\]) (. *?) (\[\/u\]) "
Strcontent=re. Replace (strcontent, "<u>$2</u>")
Re. Pattern= "(\[b\]) (. *?) (\[\/b\]) "
Strcontent=re. Replace (strcontent, "<b>$2</b>")
Re. Pattern= "(\[sup\]) (. *?) (\[\/sup\]) "
Strcontent=re. Replace (strcontent, "<sup>$2</sup>")
Re. Pattern= "(\[sub\]) (. *?) (\[\/sub\]) "
Strcontent=re. Replace (strcontent, "<sub>$2</sub>")

Re. Pattern= "\[size=" ([+|-]?[ 0-7]) \] (. *?) (\[\/size\]) "
Strcontent=re. Replace (strcontent, "<font size=$1>$2</font>")

Re. Pattern= "(\[center\]) (. *?) (\[\/center\]) "
Strcontent=re. Replace (strcontent, "<center>$2</center>")

Set re=nothing

Gmt=strcontent
End Function


Rem Filter HTML code
function Htmlfilter (fstring)
If not IsNull (fstring) Then
Fstring=server.htmlencode (fstring)
fstring = Replace (fstring, CHR (9), "") ' tab
' fstring = Replace (fstring, CHR (34), "" ") '"
' fstring = Replace (fstring, CHR (39), "'") '
fstring = Replace (fstring, CHR (13), "") ' carriage return is a 13+10
fstring = Replace (fstring, CHR (a) & CHR (a), "<P>") '
fstring = Replace (fstring, CHR (), "<BR>")
' fstring = Replace (fstring, CHR (32), "") ' Space
Htmlfilter = fstring
End If
End Function
%>
<%
Function Isemail (STRNG)
Isemail = False
Dim regEx, Match ' Create variables.
Set regEx = New RegExp ' Create a regular expression object (stupid, huh?)
Regex.pattern = "^\w+ (-\w+) | ( \.\w+)) *\@[a-za-z0-9]+ (\.| -) [a-za-z0-9]+) *\. [a-za-z0-9]+$ "' Sets pattern.
Regex.ignorecase = True ' Set case insensitivity.
Set Match = Regex.execute (strng) ' Execute search.
If Match.count then isemail= true
End Function
%>

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.