語法如下:
Sub aa()
Dim mSht As Worksheet
Dim mRng As Range, mRng1 As Range
Dim mRegexp As New RegExp
Dim mPtn$, mStr$
Dim matchCol, matchA
Dim s%
Set mRegexp = CreateObject("vbscript.regexp")
Set mSht = Worksheets("temp")
s = 1
mPtn = "\d+|PCE|\d+,[0-9]{3}" '如何修正mPtn
With mSht
Set mRng1 = .Range("a1", .Range("a" & .Rows.Count).End(xlUp))
For Each mRng In mRng1
mStr = mRng.Value
With mRegexp
.Global = True
.IgnoreCase = False
.Pattern = mPtn
Set matchCol = .Execute(mStr)
End With
For Each matchA In matchCol
mRng.Offset(, s) = matchA.Value
s = s + 1
Next
s = 1
Next
End With
End Sub
Sub aa()
Dim regex As New RegExp
Dim sr, mat, m
sr = "abc 100 元 8000 元 57 元 efg"
With regex
.Global = True
.Pattern = "\d+\s+(?=元)."
Set mat = .Execute(sr)
For Each m In mat
Debug.Print m
Next m
End With
End Sub
Sub bb()
Dim regex As New RegExp
Dim sr, mat, m
sr = "abc 100 方元 8000 方元 57 方元 efg"
With regex
.Global = True
.Pattern = "\d+\s+(?=方元)."
Set mat = .Execute(sr)
For Each m In mat
Debug.Print m
Next m
End With
End Sub作者: dechiuan999 時間: 2013-8-23 09:09