次の関数は、この問題を満たすために、マッチする文字列、キャプチャできないプレフィックスの正規表現パターン、後続のキャプチャグループの正規表現パターンを受け入れます。
Function LookBehindRegex(ByVal inputText As String, nonCaptureRegex As String, _
captureRegex As String)
'Non capturing lookbehind to retrieve reference preceded by a regex group
Dim regEx As New RegExp
Dim intermediate As String
Dim nonCaptureText As String
regEx.IgnoreCase = True
'First set the capture pattern to both regex groups, to capture the whole text
regEx.Pattern = "(" & nonCaptureRegex & ")" & "(" & captureRegex & ")"
'Store that
intermediate = regEx.Execute(inputText)(0)
'Next, set the pattern to only capture the non-capture regex
regEx.Pattern = nonCaptureRegex
'Store the non-capturable text from the intermediate result
nonCaptureText = regEx.Execute(intermediate)(0)
'Finally remove the non-capture text from the intermediate result
TestReg = Replace(intermediate, nonCaptureText, "")
End Function
制限事項:これは肯定的な視線をシミュレートするだけです。関連する正規表現モジュールは、VBプロジェクトへの参照として追加する必要があります。
あなたの答えは、キャプチャの仕組みに基づいたもう1つの通常の回避策です。さらに簡単に書くことができます。 –