Thread: [Solved] Regex-pattern
View Single Post
 
Old 01-06-2025, 11:16 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 294
vivka is on a distinguished road
Default

Or another presentation of Greg's idea:
Code:
Sub ScratchMacro()
'Coded by Gregory K. Maxey
'https://www.msofficeforums.com/184580-post31.html

 Dim oRng As range
  Set oRng = ActiveDocument.range
  With oRng.Find
    .text = "<[0-9]{4,5}>"
    .MatchWildcards = True
    While .Execute
        If InStr(oRng.text, "2") > 0 Then MsgBox oRng.text
    Wend
  End With
lbl_Exit:
  Exit Sub
  End Sub
However I had situations when regex helped me out, unlike VBA. Maybe it was because of my poor VBA knowledge.
Greg and Batman1, thank you for another good lesson!