|
'应该怎么改这个正则法?以下是兰版的正则法(数字相加)
Sub mxg()
MsgBox ns("正度0.5*0.8") '剔除文字,返回结果公式值0.4 (0.5*0.8)
End Sub
Function ns(rg)
Dim reg As New RegExp
Dim sr, ma, s, m, x
With reg
.Global = True
.Pattern = "\d*\.?\d*"
Set ma = .Execute(rg)
For Each m In ma
s = s + Val(m)
Next m
End With
ns = s
' Stop
End Function
回复 兰色幻想 的帖子
- Sub mxg()
- MsgBox ns("正度0.5*0.8+(3/2)-1")
- End Sub
- Function ns(rg As Variant) As String
- With CreateObject("vbscript.regexp")
- .Global = True
- .MultiLine = True
- .Pattern = "[\u4e00-\u9fa5]+"
- If .test(rg) Then
- ns = Format(Application.Evaluate(.Replace(rg, "")), "0.00")
- End If
- End With
- End Function
复制代码
{:111:}因为PATTERN多写了一个^
|
|