近日在vbs中遇到一个问题,先看代码:- Dim str
- str = "<br>对于他来说,保护Lj贺一鸣的任务&123序列,远在烤鱼之上,既然贺一�鸣脱离了他的视&#o39;伐范围,那么他就必须最上去。</br>"
- MsgBox RegTest(str, "<br>([^&#.*;]+)</br>")
-
- Function RegTest(vbstr, pattern)
- dim regEx, Matches, Match, regstr
- set regEx = New RegExp
- regEx.Pattern = pattern
- regEx.Global = true
- regEx.IgnoreCase = false
- set Matches = regEx.execute(vbstr)
- for each Match in Matches
- regstr = regstr & Match.value
- Next
- RegTest = regstr
- End Function
复制代码 我的原意是去掉str两头的标签以及以$#打头并以;结束的字符串(在例子中为�和&#o39;),但搞了n久都没有成功,特来请教大家,还望知道的不吝赐教于我,先在此表示感谢了!
又仔细看了正则的资料并转换了思路,成功解决,代码如下:- Dim str
- str = "<br>对于他来说,保护Lj贺一鸣的任务&123序列,远在烤鱼之上,既然贺一�鸣脱离了他的视&#o39;伐范围,那么他就必须最上去。</br>"
- MsgBox RegTest(str, "([<br>/]|&#.[0-9]+;)")
-
- Function RegTest(vbstr, pattern)
- dim regEx, Matches, Match
- set regEx = New RegExp
- regEx.Pattern = pattern
- regEx.Global = true
- regEx.IgnoreCase = false
- set Matches = regEx.Execute(vbstr)
- for each Match in Matches
- vbstr = Replace(vbstr, Match, "")
- Next
- RegTest = vbstr
- End Function
复制代码
|