VBS里正则问题

小熊开发 2008-12-05 03:31:58
<DIV class=e> <SPAN class=b>  </SPAN> <SPAN class=m><? </SPAN> <SPAN class=pi>xml version="1.0" encoding="utf-8" </SPAN> <SPAN class=m>?> </SPAN> </DIV>
<DIV class=e>
<DIV class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <A class=b onfocus=h() onclick="return false" href="#">- </A> <SPAN class=m>< </SPAN> <SPAN class=t>friend </SPAN> <SPAN class=t> uin </SPAN> <SPAN class=m>=" </SPAN> <B>641258358 </B> <SPAN class=m>" </SPAN> <SPAN class=m>> </SPAN> </DIV>
<DIV>
<DIV class=e>
<DIV class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <A class=b onfocus=h() onclick="return false" href="#">- </A> <SPAN class=m>< </SPAN> <SPAN class=t>qq </SPAN> <SPAN class=m>> </SPAN> </DIV>
<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <SPAN class=b>  </SPAN> <SPAN class=m>< </SPAN> <SPAN class=t>node </SPAN> <SPAN class=t>data </SPAN> <SPAN class=m>=" </SPAN> <B>278587249 </B> <SPAN class=m>" </SPAN> <SPAN class=t> label </SPAN> <SPAN class=m>=" </SPAN> <B>Life Goes On[278587249] </B> <SPAN class=m>" </SPAN> <SPAN class=m> /> </SPAN> </DIV> </DIV>
<DIV class=e>
<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <SPAN class=b>  </SPAN> <SPAN class=m>< </SPAN> <SPAN class=t>node </SPAN> <SPAN class=t>data </SPAN> <SPAN class=m>=" </SPAN> <B>410711783 </B> <SPAN class=m>" </SPAN> <SPAN class=t> label </SPAN> <SPAN class=m>=" </SPAN> <B>乐乐oО[410711783] </B> <SPAN class=m>" </SPAN> <SPAN class=m> /> </SPAN> </DIV> </DIV>
<DIV class=e>
<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <SPAN class=b>  </SPAN> <SPAN class=m>< </SPAN> <SPAN class=t>node </SPAN> <SPAN class=t>data </SPAN> <SPAN class=m>=" </SPAN> <B>449616391 </B> <SPAN class=m>" </SPAN> <SPAN class=t> label </SPAN> <SPAN class=m>=" </SPAN> <B>通缉犯↘婆娘[449616391] </B> <SPAN class=m>" </SPAN> <SPAN class=m> /> </SPAN> </DIV> </DIV>
<DIV class=e>
<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <SPAN class=b>  </SPAN> <SPAN class=m>< </SPAN> <SPAN class=t>node </SPAN> <SPAN class=t>data </SPAN> <SPAN class=m>=" </SPAN> <B>625281357 </B> <SPAN class=m>" </SPAN> <SPAN class=t> label </SPAN> <SPAN class=m>=" </SPAN> <B>小樱子[625281357] </B> <SPAN class=m>" </SPAN> <SPAN class=m> /> </SPAN> </DIV> </DIV>
<DIV class=e>
<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <SPAN class=b>  </SPAN> <SPAN class=m>< </SPAN> <SPAN class=t>node </SPAN> <SPAN class=t>data </SPAN> <SPAN class=m>=" </SPAN> <B>627427573 </B> <SPAN class=m>" </SPAN> <SPAN class=t> label </SPAN> <SPAN class=m>=" </SPAN> <B>葬爱·叛逆[627427573] </B> <SPAN class=m>" </SPAN> <SPAN class=m> /> </SPAN> </DIV> </DIV>
<DIV class=e>
<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <SPAN class=b>  </SPAN> <SPAN class=m>< </SPAN> <SPAN class=t>node </SPAN> <SPAN class=t>data </SPAN> <SPAN class=m>=" </SPAN> <B>913498645 </B> <SPAN class=m>" </SPAN> <SPAN class=t> label </SPAN> <SPAN class=m>=" </SPAN> <B>早些说出来~[913498645] </B> <SPAN class=m>" </SPAN> <SPAN class=m> /> </SPAN> </DIV> </DIV>
<DIV> <SPAN class=b>  </SPAN> <SPAN class=m></ </SPAN> <SPAN class=t>node </SPAN> <SPAN class=m>> </SPAN> </DIV> </DIV> </DIV>
<DIV class=e>
<DIV class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <A class=b onfocus=h() onclick="return false" href="#">- </A> <SPAN class=m>< </SPAN> <SPAN class=t>node </SPAN> <SPAN class=t> label </SPAN> <SPAN class=m>=" </SPAN> <B>兄弟)(解情 </B> <SPAN class=m>" </SPAN> <SPAN class=m>> </SPAN> </DIV>

<DIV style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <SPAN class=b>  </SPAN> <SPAN class=m>< </SPAN> <SPAN class=t>pp </SPAN> <SPAN class=m>/> </SPAN> </DIV> </DIV>
<DIV> <SPAN class=b>  </SPAN> <SPAN class=m></ </SPAN> <SPAN class=t>friend </SPAN> <SPAN class=m>> </SPAN> </DIV> </DIV> </DIV>

上面代码是a.txt这个文件里面的内容。。我想用VBS把里面的内容用正则替换。。意思就是提取像 <B>709514182 </B>和 <B>桃园民[897315710] </B>中 <B>…… </B>之间的“709514182”和“桃园民[897315710]”这样的字符串 然后再把它写入b.txt或者原来的a.txt都行

提取 <B>…… </B>之间的内容的正则表达示是 " <B>(.+/?) </B>"

提取后的效果是这样的
我的好友
468192 傀儡[468192]
11979791 逝.[11979791]
13994674 ????″結裹?.[13994674]
53338000 飘逸[53338000]
53966857 н∪Ⅰ╃∑[53966857]
85895800 使 命[85895800]
86467129 伍線譜[86467129]
112992341 迷蝶晓梦[112992341]
136270231 阿灬楓[136270231]
200752222 拓跋孤星[200752222]
251499940 烟花中的风铃[251499940]
263698430 等,劫个色[263698430]
272993325 ヤ從新ツ徕过[272993325]
285932320 ゞ爱情O度[285932320]
290871794 千雨*冰[290871794]
371971450 紫垣Ж俱灭[371971450]
375492608 梦飞鸟[375492608]
601349162 吸血鬼gri$%#[601349162]
603283554 幽默☆王子[603283554]
785972660 風 吹 雲 飛[785972660]
798962284 尛焺VS濤凞[798962284]
836117099 :~╳灬戀↗迩[836117099]
841185101 小鱼儿[841185101]
873274396 Y Y威妮熊[873274396]
907307861 ♀快乐天使≌[907307861]
929663283 I LOVE ?[929663283]

!核K……
18115136 等你等到我心[18115136]
249247026 Sunshine[249247026]
364838962 野人卐归来[364838962]
372791148 °自甴⒐恏ゞ[372791148]
572929516 爱你到永远[572929516]
815134221 冷[815134221]

徒弟“”
34507945 艹夜丶蒾離灬[34507945]
471614870 冰袭/月亮[471614870]
630052991 í00O0[630052991]
981726584 皵巢咖啡[981726584]

无奇 }{
273214981 找寻[273214981]
278587249 Life Goes On[278587249]
410711783 乐乐oО[410711783]
449616391 通缉犯↘婆娘[449616391]
625281357 小樱子[625281357]
627427573 葬爱·叛逆[627427573]
913498645 早些说出来~[913498645]

兄弟)(解情
137101840 雾霭烟波[137101840]
284482870 嗳o裥簞[284482870]
897315710 桃园民[897315710]

忘大家帮我啊。。弄了几天都没弄出来。。。我是菜哈
...全文
113 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小熊开发 2008-12-05
  • 打赏
  • 举报
回复
研究了一大半天。。差不多了。。高手完善一下啊。。。
Msgbox RegExpTest(ReadText("a.txt"))

Function RegExpTest(strng)
Set RegEx1=New RegExp
RegEx1.Pattern="<b>([^<]*)</b>" '搜索字符串,括号用来定义子集
RegEx1.IgnoreCase=True 'True不区分大小写,False区分
RegEx1.Global=True 'Fasle只匹配第一个,True匹配全部
Set A=RegEx1.Execute(strng)
For Each x In A
i=i+1
y=y & x.SubMatches(0)
If i Mod 2 = 0 Then
y=y & vbCrLf
End If
Next
RegExpTest=y
End Function



Function ReadText(FilePath)
Dim Fso,Rso
Set Fso=CreateObject("Scripting.FileSystemObject")
Set Gso=Fso.GetFile(FilePath)
Set Rso=Gso.OpenAsTextStream(1)
ReadText=Rso.ReadAll
End Function
小熊开发 2008-12-05
  • 打赏
  • 举报
回复
表达示是对的。。可以就是撮出来以后。。他排版不对的。。全接在一起来。。我要它像这样啊。。
我的好友
468192 傀儡[468192]
11979791 逝.[11979791]
13994674 ????″結裹?.[13994674]
53338000 飘逸[53338000]
53966857 н∪Ⅰ╃∑[53966857]
85895800 使 命[85895800]
86467129 伍線譜[86467129]
112992341 迷蝶晓梦[112992341]
136270231 阿灬楓[136270231]
200752222 拓跋孤星[200752222]
251499940 烟花中的风铃[251499940]
263698430 等,劫个色[263698430]
272993325 ヤ從新ツ徕过[272993325]
285932320 ゞ爱情O度[285932320]
290871794 千雨*冰[290871794]
371971450 紫垣Ж俱灭[371971450]
375492608 梦飞鸟[375492608]
601349162 吸血鬼gri$%#[601349162]
603283554 幽默☆王子[603283554]
785972660 風 吹 雲 飛[785972660]
798962284 尛焺VS濤凞[798962284]
836117099 :~╳灬戀↗迩[836117099]
true_guowei 2008-12-05
  • 打赏
  • 举报
回复
这个正则表达式要是对的话,就直接用啊?Maths啊,楼主的问题是什么啊?
true_guowei 2008-12-05
  • 打赏
  • 举报
回复
这个正则表达式要是对的话,就直接用啊?Maths啊,楼主的问题是什么啊?
tianshangfei 2008-12-05
  • 打赏
  • 举报
回复
up
小熊开发 2008-12-05
  • 打赏
  • 举报
回复
代码改进了。。高手在改进一下
wscript.echo RegExpTest(ReadText("a.txt"))
Function RegExpTest(strng)
Set RegEx1=New RegExp
RegEx1.Pattern="<b>([^<]*)</b>" '搜索字符串,括号用来定义子集
RegEx1.IgnoreCase=True 'True不区分大小写,False区分
RegEx1.Global=True 'Fasle只匹配第一个,True匹配全部
Set A=RegEx1.Execute(strng)
For Each x In A
i=i+1
y=y & x.SubMatches(0)
If i Mod 2 = 0 Then
y=y & vbCrLf
else
y=y & " "
End If
Next
RegExpTest=y
End Function

Function ReadText(FilePath)
Dim Fso,Rso
Set Fso=CreateObject("Scripting.FileSystemObject")
Set Gso=Fso.GetFile(FilePath)
Set Rso=Gso.OpenAsTextStream(1)
ReadText=Rso.ReadAll
End Function


str = RegExpTest(ReadText("a.txt"))



Set objie=WScript.CreateObject("internetexplorer.application")
objie.Navigate("about:blank")
objie.Document.parentwindow.clipboarddata.setdata "text",str
objie.Quit



on error resume next

Set ie=createobject("internetexplorer.application")
ie.navigate "about:blank"
ie.visible=False

set fso=createobject("scripting.filesystemobject")
set f=fso.opentextfile("QQ.txt",2,true)

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
str = objIE.document.parentwindow.clipboardData.GetData("text")
objIE.Quit
f.write str
f.close

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧