vbs 有点长- Function getTextStr(ByVal strSrcFile, strPattern, strDstFile)
- Dim fso, objFile, strText, objReg, objMatch, str
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set objFile = fso.OpenTextFile(strSrcFile, 1)
- strText = objFile.ReadAll
- objFile.Close
- str = ""
- Set objReg = New RegExp
- objReg.MultiLine = True
- objReg.Global = True
- objReg.Pattern = strPattern
- For Each objMatch In objReg.Execute(strText)
- str = str + objMatch.Value + vbCrLf
- Next
- Set objFile = fso.OpenTextFile(strDstFile, 2, True)
- objFile.Write str
- objFile.Close
- Set objFile = Nothing
- Set fso = Nothing
- End Function
-
- Dim strSrcFile
- strSrcFile = "a.txt"
- getTextStr strSrcFile, "^\S+\s+\w*?([A-Z]\w*?\d\w*|\d\w*?[A-Z]\w*)$", "1.txt"
- getTextStr strSrcFile, "^\S+\s+\d+$", "2.txt"
- getTextStr strSrcFile, "^\S+\s+[a-zA-Z]+$", "3.txt"
复制代码
|