I've got the following code, which I created with your help a few months ago. It searches a Word document for instances of Doc IDs in a format <[A-Z]{3,}.[0-9]{4}.[0-9]{4}.[0-9]{4}, and then hyperlinks them.

Code:

Sub AddHyperlinks()
Application.ScreenUpdating = False
Dim wdDoc As Document
Set wdDoc = ActiveDocument
'This first loop searches the body of the document
With wdDoc.Range
With .Find
.ClearFormatting
'This searches for a reference of XXX+.0000.0000.0000 (where XXX+ is equal to at least 3 letters). If the references are different to this, change the next line of code.
.Text = "<[A-Z]{3,}.[0-9]{4}.[0-9]{4}.[0-9]{4}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
'Change the web address here to reflect the web address of the current e-file
.Hyperlinks.Add Anchor:=.Duplicate, Address:="https://[redacted]" & .Text & ".PDF", TextToDisplay:=.Text
.End = .End + 1
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With

'This next loop searches the footnotes, if there are any
If ActiveDocument.Footnotes.Count >= 1 Then
With wdDoc.StoryRanges(wdFootnotesStory)
With .Find
.ClearFormatting
'This searches for a reference of XXX+.0000.0000.0000 (where XXX+ is equal to at least 3 letters). If the references are different to this, change the next line of code.
.Text = "<[A-Z]{3,}.[0-9]{4}.[0-9]{4}.[0-9]{4}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
'Change the web address here to reflect the web address of the current e-file
.Hyperlinks.Add Anchor:=.Duplicate, Address:="https://[redacted]" & .Text & ".PDF", TextToDisplay:=.Text
.End = .End + 1
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
End If

Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

I've now been told it needs to search for Doc IDs formatted as <[A-Z]{3,}.[0-9]{4}.[0-9]{4}.[0-9]{4} OR <[A-Z]{3,}.[0-9]{4}.[0-9]{4}. I tried simply adding another loop to search for the shorter string first, but that just puts a short string link on the longer strings (ie, if the Doc ID is AAA.0000.0001.0002, it only links as AAA.000.0001), and I then tried doing the shorter string last, but that actually deletes the last part of the Doc ID altogether. Fun fun.

So, is there a way I can add an OR to the string search? I tried just doing this, but obviously that didn't work!