本帖最后由 autoav 于 2020-5-18 14:32 编辑
回复 2# smss
http://www.bathome.net/thread-30879-1-1.html
例子倒是有点看懂了,但是在RegEx()如何才能反复替换,现在文件执行一次,只能替换一次- Function RegEx(txt)
- Dim re, s, i, s1, ss
- Set re = New RegExp
- re.Pattern = "(第)([" & str & "]+)(章)"
- If Not re.Test(txt) Then RegEx = txt : Exit Function
- s = re.Execute(txt)(0).SubMatches(1) : s = Replace(s, "两", "二")
- If Left(s, 1) = "十" Then s = "一" & s
- For i = 1 to Len(s)
- s1 = Mid(s, i, 1)
- If InStr(str, s1) > 10 Then
- ss = ss & "*10^" & (InStr(str, s1)-10) & "+"
- Else ss = ss & (InStr(str, s1)-1)
- End If
- Next
- s = Right("0000" & eval(ss & "+0"), 4)
- RegEx = re.Replace(txt, "$1" & s & "$3")
- End Function
复制代码
|