7,763
社区成员
发帖
与我相关
我的任务
分享
Public Sub TestRegex03()
Dim s As String = "1、广州/深圳/珠海/佛山" + vbCrLf + "2、www.baidu.com/abc/123/bcd/456.html" + vbCrLf + "3、广州市天河北路,510000/深圳市福田区,5100003" + vbCrLf + "4、【广东】广州天河区中山大道88号winte酒吧" + vbCrLf + "5、www.Google.com/abc/123/bcd/456.html"
Dim result As String = Regex.Replace(s, "(?<=(?<ac>[\u4E00-\u9FA5])|(?<al>[a-zA-Z])|(?<ad>[0-9]))+(/)(?=(?<bc>[\u4E00-\u9FA5])|(?<bl>[a-zA-Z])|(?<bd>[0-9]))+|(?<remove>([\r\n]+|^)\s*[^\r\n]*?【[\u4E00-\u9FA5]+】[^\r\n]*([^\r\n]|$))", Function(m As Match) IIf(m.Groups("ac").Success And m.Groups("bc").Success, ";", IIf((m.Groups("ac").Success And m.Groups("bd").Success) Or (m.Groups("ad").Success And m.Groups("bc").Success), vbCrLf + " ", IIf(m.Groups("remove").Success, "", m.Value))))
Console.WriteLine(result)
End Sub
1、广州;深圳;珠海;佛山
2、www.baidu.com/abc/123/bcd/456.html
3、广州市天河北路,510000
深圳市福田区,5100003
5、www.Google.com/abc/123/bcd/456.html
Sub GetNewTxt()
Dim oJs As Object, Str$
Set oJs = CreateObject("ScriptControl"): oJs.Language = "JScript"
oJs.eval "function gets(str){return str.replace(/(^|\s)\【\S+/g,'') " _
& ".replace(/(\d+)(\/)(?=[一-龥])/g,'$1 ') " _
& ".replace(/\/(?=[一-龥])/g,';')}"
Open App.Path & "\001.txt" For Input As #1
Str = Replace(Replace(StrConv(InputB(LOF(1), 1), vbUnicode), " ", "↑"), vbCrLf, " "): Reset
Str = Replace(oJs.codeobject.gets(Str), " ", vbCrLf)
Open App.Path & "\001.txt" For Output As #1
Print #1, Replace(Str, "↑", " "): Reset
End Sub
Sub GetNewTxt()
Dim oJs As Object, Str$
Set oJs = CreateObject("ScriptControl"): oJs.Language = "JScript"
oJs.eval "function gets(str){return str.replace(/(^|\s)\S+?【\S+/g,'') " _
& ".replace(/(\d+)(\/)(?=[一-龥])/g,'$1 ') " _
& ".replace(/\/(?=[一-龥])/g,';')}"
Open App.Path & "\001.txt" For Input As #1
Str = Replace(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf, " "): Reset
Str = Replace(oJs.codeobject.gets(Str), " ", vbCrLf)
Open App.Path & "\001.txt" For Output As #1
Print #1, Str: Reset
End Sub
Sub GetNewTxt()
Dim oJs As Object, Str$
Set oJs = CreateObject("ScriptControl"): oJs.Language = "JScript"
oJs.eval "function gets(str){return str.replace(/(^|\s)\S+【\S+/g,'') " _
& ".replace(/(\d+)(\/)(?=[一-龥])/g,'$1 ') " _
& ".replace(/\/(?=[一-龥])/g,';')}"
Open App.Path & "\001.txt" For Input As #1
Str = Replace(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf, " "): Reset
Str = Replace(oJs.codeobject.gets(Str), " ", vbCrLf)
Open App.Path & "\002.txt" For Output As #1
Print #1, Str: Reset
End Sub
Sub GetNewTxt()
Dim oJs As Object, Str$
Set oJs = CreateObject("ScriptControl"): oJs.Language = "JScript"
oJs.eval "function gets(str){return str.match(/(^|\s)\S+\/\S+/g,'').join('') " _
& ".replace(/(\d+)(\/)(?=[一-龥])/g,'$1 ') " _
& ".replace(/\/(?=[一-龥])/g,';')}"
Open App.Path & "\001.txt" For Input As #1
Str = Replace(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf, " "): Reset
Str = Replace(oJs.codeobject.gets(Str), " ", vbCrLf)
Open App.Path & "\002.txt" For Output As #1
Print #1, Str: Reset
End Sub
Sub GetNewTxt()
Dim oJs As Object, Str$
Set oJs = CreateObject("ScriptControl"): oJs.Language = "JScript"
oJs.eval "function gets(str){return str.match(/(^|\s)\S+\/\S+/g,'').join(' ').replace(/\/(?=[一-龥])/g,';')}"
Open App.Path & "\001.txt" For Input As #1
Str = Replace(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf, " "): Reset
Str = Replace(oJs.codeobject.gets(Str), " ", vbCrLf)
Open App.Path & "\001.txt" For Output As #1
Print #1, Str: Reset
End Sub