以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]正则表达式查找移动 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=101440) |
-- 作者:黄训良 -- 发布时间:2017/5/31 15:22:00 -- [求助]正则表达式查找移动 原文本如下: <UL> <LI> MotionFrame Property <a href="html/82f19ef7-4958-d144-1888-6165e24e18a9.htm" > </a> </LI> </UL> <UL> <LI> MotionLevel Property <a href="html/9737e2b9-e40d-1f22-b272-393630517695.htm" > </a> </LI> </UL> <UL> <LI> SuppressNoise Property <a href="html/2953d218-9e8e-b2a8-9eb4-19cf6ec363f9.htm" > </a> </LI> </UL> 实现目的(即把红色文本移动到现在的位置): <UL> <LI> <a href="html/82f19ef7-4958-d144-1888-6165e24e18a9.htm" > MotionFrame Property</a> </LI> </UL> <UL> <LI> <a href="html/9737e2b9-e40d-1f22-b272-393630517695.htm" > MotionLevel Property</a> </LI> </UL> <UL> <LI> <a href="html/2953d218-9e8e-b2a8-9eb4-19cf6ec363f9.htm" > SuppressNoise Property</a> </LI> </UL> |
-- 作者:有点色 -- 发布时间:2017/5/31 16:01:00 -- Dim str As String = FileSys.ReadAllText("g:\\test.txt", Encoding.Default) str = str.replace(chr(10), "").Replace(chr(13), "") Dim mc1 = System.Text.RegularExpressions.Regex.Matches(str,"<LI>.+?</LI>") For i As Integer = 0 To mc1.count-1 Dim s As String = mc1(i).value Dim idx As Integer = s.IndexOf("<a ") Dim ns As String = s.SubString(4, idx-4) Dim ns2 As String = s.Replace(ns, "") Dim idx2 As Integer = ns2.IndexOf("</a>") ns2 = ns2.Insert(idx2, ns.trim) str = str.Replace(s, ns2) Next output.show(str) |
-- 作者:黄训良 -- 发布时间:2017/5/31 17:47:00 -- 厉害,谢谢! |