VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "DetectorRegex"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ====== Regular expression based detector =======
' Shared module version: 20220613
' Tested in:
' Depends on:
' Required reference: VBScript_RegExp_55
Option Explicit

Private regex_ As RegExp

Public Function Init(theRegex As RegExp)
  Set regex_ = theRegex
End Function

Public Function Test(sText$) As Boolean
  Dim matches As Object: Set matches = regex_.Execute(sText)
  If matches.Count <> 1 Then _
    Exit Function
  Test = matches.Item(0).Length = VBA.Len(sText)
End Function

Public Function ExtractFragments(sText$) As PC_ParsedData
  Dim iData As New PC_ParsedData
  
  Dim matches As Object: Set matches = regex_.Execute(sText)
  Dim nMatch&
  For nMatch = 0 To matches.Count - 1 Step 1
    Dim nStart&: nStart = matches.Item(nMatch).FirstIndex
    Dim nEnd&: nEnd = nStart + matches.Item(nMatch).Length
    Call iData.AddItem(nStart, nEnd)
  Next nMatch
  
  Set ExtractFragments = iData
End Function
