У меня есть шаблон REGEX, который я унаследовал, который, кажется, работает в онлайн-тестерах (демонстрация здесь: https://regex101.com/r/KPpoLS/1)
Однако, он использует отрицательные взгляды, чтобы избежать захвата субстанций более длинные серийные номера. Мне нужно использовать этот шаблон REGEX в макросе VBA для идентификации всех шаблонов номеров серийных номеров (перечисленных ниже) - но VBA не поддерживает отрицательные взгляды из того, что я могу сказать.
К сожалению, я не достаточно разбираюсь в REGEX, чтобы реорганизовать этот шаблон REGEX - кто-нибудь может предложить какие-либо предложения?
\b(?<!-)(\d\/[A-Z]{2}\/\d{6}-\d{2})|([A-Z]-\d\/[A-Z]{2}\/\d{6}-\d{2})|(?<![A-Z])([A-Z]\/[A-Z]{2}\/\d{6}-\d{2})|([A-Z]{2}\/[A-Z]{2}\/\d{6}-\d{2})|([A-Z][0-9]\/[A-Z]{2}\/\d{6}-\d{2})|(?<![A-Z])([A-Z]-[A-Z]{3}\/\d{6}-\d{2})|([0-9]\/[A-Z]{2}\/[A-Z]{3}\/\d{6}-\d{2})|([A-Z]\/[A-Z]{2}\/[A-Z]{3}\/\d{6}-\d{2})|([0-9]\/[A-Z]{2}\/[A-Z]{3}\/\d{4}-\d{2})|([0-9]\/[A-Z]{2}\/[A-Z]{3}\/\d{6}-\d{2})
[list arranged by sub-strings]
1/AA/111111-11
A-1/AA/111111-11
A/AA/111111-11
AA/AA/111111-11
A1/AA/111111-11
A-AAA/111111-11
1/AA/AAA/111111-11
A/AA/AAA/111111-11
1/AA/AAA/1111-11
[orginal list]
1/AA/111111-11
A/AA/111111-11
A1/AA/111111-11
AA/AA/111111-11
A-AAA/111111-11
1/AA/AAA/1111-11
A-1/AA/111111-11
1/AA/AAA/111111-11
A/AA/AAA/111111-11
Sub regex_test_by_word_story_ranges()
Dim stringone As String
Dim regexone As Object
Dim doc As Word.Document
Dim rng As Word.Range
Dim para As Word.Paragraph
Dim i as Long
Dim x As Long
Dim regcount As Long
Dim rngstory As Range
Dim serialArray() as String
Set regexone = New RegExp
Set doc = ActiveDocument
'=========================================
'Loop #1 to find Category 1 serial numbers
'=========================================
regexone.Pattern = ""
regexone.Global = True
regexone.Pattern = IgnoreCase
For Each rngstory in doc.StoryRanges
On Error Resume Next
rngstory.Select
stringone = stringone & rngstory.Text
Next rngstory
Set theMatches = regexone.Execute(stringone)
regcount = theMatches.Count
debug.print regcount
With theMatches
If .Count > 0 Then
ReDim Preserve serialArray(.Count, 5)
x = 1
For Each Match In theMatches
debug.print Match.value
serialArray(x, 1) = Match.value 'this will become a seach term for another macro
serialArray(x, 2) = Replace(Match.value, "/", "!") 'this will becom part of a URL
serialArray(x, 3) = "www.baseURL.com/" & Replace(Match.value, "/", "!") 'This is a base URL, which (X, 2) on the end. Search term from next macro will find and insert this hyperlink
serialArray(x, 4) = "Placeholder3" 'extra, will delete
serialArray(x, 5) = "Placeholder4" 'extra, will delete
x = x + 1
Next Match
End If
End With
'checking output of array:
For x = LBound(serialArray) To UBound(serialArray)
debug.print serialArray(x, 1) & ", " & serialArray(x, 2) & ", " & serialArray(x, 3) & ", " & serialArray(x, 4) & ", " & serialArray(x, 5)
Next x
'=========================================
'Loop #2 to find Category 2 serial numbers
'=========================================
'Same loop as above code, but I have not developed the REGEX for Category 2 serial numbers yet
'Loop #2 need add Matches from Loop #2 REGEX to the serialArray()
'This portion is beyond my original question, but would welcome any help on adding subsequent loop matches to the serialArray()
'https://stackoverflow.com/questions/60831517/alternative-to-negative-lookbehinds-in-vba-macro?noredirect=1#comment107630601_60831517
End Sub