试试- Rem On Error Resume Next
- Dim srcFile, dstFile, fso, objFile
- srcFile = "in.txt" '输入文件
- dstFile = "out.txt" '输出文件
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set objFile = fso.OpenTextFile(srcFile, 1)
-
- Dim reg1, strLine, n, out(), match, reg2, s
- Set reg1 = New RegExp
- Set reg2 = New RegExp
- reg1.Pattern = "^\s*\(\s*(?=([^)\s]+))\1\s+(?=([^)]+))\2\)\s*$"
- reg2.Pattern = "(?:\S+\s+){9}(?=(\S+))\1(?!\s*$)"
- reg2.Global = True
- n = 0
-
- while Not objFile.AtEndOfStream
- ReDim Preserve out(n)
- strLine = objFile.ReadLine
- If reg1.Test(strLine) Then
- Set match = reg1.Execute(strLine)(0)
- s = Replace(match.SubMatches(1), "-", ".")
- s = reg2.Replace(s, "$&," + vbCrLf + " ")
- out(n) = match.SubMatches(0) + ";" + s
- Else
- out(n) = strLine
- End If
- n = n + 1
- wend
-
- objFile.Close
- fso.OpenTextFile(dstFile, 2, True).Write Join(out, vbCrLf)
-
- MsgBox "Done"
复制代码
|