Thread: [Solved] Regex-pattern
View Single Post
 
Old 01-06-2025, 11:33 AM
batman1 batman1 is offline Windows 11 Office 2013
Advanced Beginner
 
Join Date: Jan 2025
Posts: 57
batman1 is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
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
As I explained the number DOES NOT HAVE TO be a word, it can be part of a word.

If the data is:
a3452b
13452
then the code with .text = "[0-9]{4,5}" will find both 3452 and 13452. Meanwhile, the result 13452 is not good because 2 appears in the fifth place and not in 1-4