本帖最后由 xp3000 于 2015-6-3 09:02 编辑
说真的还真不会,平时只在软件里面用正则表达式折腾,下面替换的怎么一次处理两条替换?有没有可以优化的地方?
^起始位置和$结束位置在这里真不知道怎么弄- Dim str, fso, file, f, txt
- Set fso = CreateObject("Scripting.FileSystemObject")
- For Each file in fso.GetFolder(".").Files
- If LCase(Right(file, 4)) = ".txt" Then
- Set f = fso.OpenTextFile(file, 1)
- txt = f.ReadAll
- f.Close : Set f = Nothing
- fso.OpenTextFile(file, 2).Write RegEx(txt)
- End If
- Next
- Set fso = Nothing
-
- MsgBox "OK"
-
- Function RegEx(txt)
- Set re = New RegExp
- re.Pattern = "第?(第[一二两三四五六七八九十○零百千0-9]{1,9})(章|节|卷)\s?(.{0,15})(?=[\r\n])"
- re.Global = True
- re.IgnoreCase = True
- RegEx = re.Replace(txt, "$1$2 $3")
- End Function
复制代码
|