ASP,vbs正则轮翻在文章段落后加上网址,网站名称,网站介绍等内容< script language ="vbs" >
'函数名称:RegExpTest
'参数: strng--》要处理的字符串;patrn--》以|隔开的各种结尾标志如:< br/ >|< /p >|< br >; patrn2--》要替换成的字符串,也以|隔
开
'作者:柳永法(yongfa365)'Blog
'功能:将strng字符串内的以patrn结束的字符后边随机的加上patrn2里的内容
Function RegExpTest(strng, patrn, patrn2)
Dim regEx, Match, Matches ' 建立变量。
Set regEx =New RegExp ' 建立正 则表达式。
regEx.IgnoreCase =True' 设置是否区分字符大小写。
regEx.Global =True' 设置全局可用性。
patrn = Split(patrn,"|")
ForEach p in patrn
regEx.Pattern = p ' 设置模式。
strng = regEx.Replace(strng,"||"& Chr(10)& p)
Next
strng = Split(strng,"||")
ForEach E in strng
s = s + E + arrArt(patrn2)
Next
RegExpTest = s
EndFunction
Function arrArt(patrn2)
arrArti = Split(patrn2,"|")
Randomize
arrArt = arrArti(CInt(UBound(arrArti)* Rnd))
EndFunction
strng ="111< br/ >222< /p >333< br/ >444< /p >555< Br >666< /P >111"
Source = strng
patrn ="< br/ >|< /p >|< br >"
patrn2 ="www.xiaoshuo8.net|http://www.ve***vb.com/blog|hi.baidu.com/"
words = RegExpTest(strng, patrn, patrn2)
MsgBox(words)
< /script >
< script >
document.Write "< fieldset >< legend >原字符串< /legend >"+ Source +"< /fieldset >< br >"
document.Write "< fieldset >< legend >转换后字符串< /legend >"+ words +"< /fieldset >< br >"
< /script >