Remember to paste a ubb code into html format, read the source code of ubb a few days ago. So with this new version. Note that this version may not work properly yet. For details, see note.
This code converts user-entered ubb code into html format. Note that Script Engine 5.0 is required (
RegExp object used)
Note: Using () in pattern will know the value found in regexp memory, $1 is the first (), and the rest is similar. But for $2
The syntax is not supported by vbscript. dll of version 5.0. I checked the version on my machine (I installed ie 5.5 ),
It is found that the vbscript. dll version is 5.50.4629, And the last modification date is July 29, December 25. This version supports $1 and other languages.
This simple improvement gradually makes regexp's function closer to perl's regular expression.
Function UBBCode (strContent)
Dim objRegExp
Set objRegExp = new RegExp
ObjRegExp. IgnoreCase = true
ObjRegExp. Global = True
'Url
ObjRegExp. Pattern = "([URL]) (http: // S ++ ?) ([/URL])"
StrContent = objRegExp. Replace (strContent, "<a href =" "$2" "TARGET = _ blank> $2 </A> ")
ObjRegExp. Pattern = "([URL]) (S ++ ?) ([/URL])"
StrContent = objRegExp. Replace (strContent, "<a href =" "http: // $2" "TARGET = _ blank> $2 </A> ")
'Email
ObjRegExp. Pattern = "([EMAIL]) (S ++ @ S ++ ?) ([/EMAIL])"
StrContent = objRegExp. Replace (strContent, "<a href =" "mailto: $2" ">2 2 </A> ")
ObjRegExp. Pattern = "([IMG]) (S ++ ?) ([/IMG])"
StrContent = objRegExp. Replace (strContent, " ")
ObjRegExp. Pattern = "([QUOTE]) (. + ?) ([/QUOTE])"
StrContent = objRegExp. Replace (strContent, "<BLOCKQUOTE> <font size = 1
Face = "" Verdana, Arial ""> quote: </font> <HR> $2 <HR> </BLOCKQUOTE> ")
ObjRegExp. Pattern = "([I]) (. + ?) ([/I])"
StrContent = objRegExp. Replace (strContent, "<I> $2 </I> ")
ObjRegExp. Pattern = "([B]) (. + ?) ([/B])"
StrContent = objRegExp. Replace (strContent, "<B> $2 </B> ")
Set objRegExp = Nothing
UBBCode = strContent