<%Public Function Ubbcode(strcontent)dim reSet re=new RegExpre.IgnoreCase =truere.Global=True'strcontent=Replace(strcontent,"file:","file :")'strcontent=Replace(strcontent,"files:","files :")'strcontent=Replace(strcontent,"script:","script :")'strcontent=Replace(strcontent,"js:","js :")'圖片UBBre.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>")'鏈接UBBre.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"">")'郵箱UBBre.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"">")
2 回答

炎炎設計
TA貢獻1808條經驗 獲得超4個贊
在replace函數中,$1,$2,$3,可以分別用來表示:
正則表達式中,匹配出的第1、2、3個子表達式。
但如果$1,$2,$3直接寫在正則表達式中,是不合法的。
這串HTML代碼中的$1,$2,$3其實和正則表達式無關,只是變量,起占位的作用:
在服務器端,會通過腳本(如Node.js)將HTML文件中的$1,$2,$3批量替換為實際字符串。

慕姐8265434
TA貢獻1813條經驗 獲得超2個贊
$1,$2,$3和正則表達式無關,這個代碼應該是放在服務器上運行的,相當于一個變量。執行完之后,$1,$2,$3就被賦予實際的值了。這里起個站位的作用。
正則表達式內容有點多哦,大概說一下
^表示開始
$結尾
\用來轉義
[a-z]指的范圍在a-z
[a-z]{6}6位a-z范圍的值
[a-z]*不限制長度范圍
添加回答
舉報
0/150
提交
取消