<%
Public Function Ubbcode(strcontent)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
'strcontent=Replace(strcontent,"file:","file :")
'strcontent=Replace(strcontent,"files:","files :")
'strcontent=Replace(strcontent,"script:","script :")
'strcontent=Replace(strcontent,"js:","js :")
'图片UBB
re.pattern="\[img\](http|https|ftp):\/\/(.[^\[]*)\[\/img\]"
strcontent=re.replace(strcontent,"<a onfocus=""this.blur()"" href=""$1://$2"" target=new><img src=""$1://$2"" border=""0"" alt=""按此在新窗口浏览图片"" onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></a>")
'链接UBB
re.pattern="(\[url\])(.[^\[]*)(\[url\])"
strcontent= re.replace(strcontent,"<a href=""$2"" target=""new"">$2</a>")
re.pattern="\[url=(.[^\[]*)\]"
strcontent= re.replace(strcontent,"<a href=""$1"" target=""new"">")
'邮箱UBB
re.pattern="(\[email\])(.*?)(\[\/email\])"
strcontent= re.replace(strcontent,"<img align=""absmiddle"" ""src=image/email1.gif""><a href=""mailto:$2"">$2</a>")
re.pattern="\[email=(.[^\[]*)\]"
strcontent= re.replace(strcontent,"<img align=""absmiddle"" src=""image/email1.gif""><a href=""mailto:$1"" target=""new"">")
问题如题目,最好给我稍微解释下一两个正则表达式替换是怎么实现的,随便说说就行!满意加分!
在replace函数中,$1,$2,$3,可以分别用来表示:
正则表达式中,匹配出的第1、2、3个子表达式。
但如果$1,$2,$3直接写在正则表达式中,是不合法的。
这串HTML代码中的$1,$2,$3其实和正则表达式无关,只是变量,起占位的作用:
在服务器端,会通过脚本(如Node.js)将HTML文件中的$1,$2,$3批量替换为实际字符串。