Quote:
Originally Posted by gmaxey
This post is a continuation of a discuss that started here:
https://www.msofficeforums.com/word-...x-pattern.html
Code:
Sub ScratchMacroC()
Dim oRng As Range
Set oRng = ActiveDocument.Range
Dim lngIndex As Long
With oRng.Find
.Text = "[0-9]{1,}"
.MatchWildcards = True
While .Execute
lngIndex = 1
If InStr(Left(oRng.Text, 4), "2") > 0 Then
Select Case Len(oRng.Text)
Case Is > 4
Debug.Print Left(oRng.Text, 5)
lngIndex = 5
Case Is = 4
Debug.Print oRng.Text
lngIndex = 4
End Select
End If
oRng.End = oRng.Start + lngIndex
Wend
End With
lbl_Exit:
Exit Sub
End Sub
|
I tested it with some data and the code works fine.
In my post #26 I quoted vivek (he later deleted it): "Sometimes regex is more functional than Word standard instruments". And in my opinion there is a code with Regex simpler than Sub ScratchMacroC