Imports System.Text.RegularExpressions Imports WINDREAMLib Public Class clsNIFulltext Public Shared Function GetValuesFromFulltext(fulltext As String, pattern As String, Pos_From As Integer, Pos_To As Integer, ignorewhitespace As Boolean) Try fulltext = fulltext.Replace(vbCrLf, "") If ignorewhitespace = True Then fulltext = fulltext.Replace(" ", "") End If Dim Ergebnis As String() ' einen Regulären Ausdruck laden Dim regulärerAusdruck As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(pattern) 'Instantiate the regular expression object. Dim r As Regex = New Regex(pattern, RegexOptions.IgnoreCase) ' Match the regular expression pattern against a text string. Dim regexMatch As Match = r.Match(fulltext) ' die Vorkommen im Volltext auslesen Dim elemente As System.Text.RegularExpressions.MatchCollection = regulärerAusdruck.Matches(fulltext) ' alle Vorkommen der windream-Indexe im SQL-String durchlaufen Dim Gesamtanzahl As Integer = 0 Dim Exit_For = False 'ClassLoggerNI.Add("Matches-Count fürm Regex is 0", False) 'Dim m1 As Match = Regex.Match(fulltext, pattern) 'If m1.Success Then ' Console.WriteLine("Match: {0}", m1.Value) ' For grpCtr As Integer = 1 To m1.Groups.Count - 1 ' Dim grp As Group = m1.Groups(grpCtr) ' Console.WriteLine("Group {0}: {1}", grpCtr, grp.Value) ' MsgBox("Group {0}: {1}", grpCtr, grp.Value) ' For capCtr As Integer = 0 To grp.Captures.Count - 1 ' Console.WriteLine(" Capture {0}: {1}", capCtr, ' grp.Captures(capCtr).Value) ' Next ' Next 'Else ' ClassLoggerNI.Add("The match for groups failed.", False) 'End If Dim matchcount As Integer = 0 If regexMatch.Success = False Then ClassLoggerNI.Add(">> ACHTUNG: Keine Vorkommen für diese Regular Expression gefunden", False) Return Nothing Else If (regexMatch.Groups.Count - 1) >= 1 Then If My.Settings.vLogErrorsonly = False Then ClassLoggerNI.Add(" >> Using RegexGroups....MatchCount(" & regexMatch.Groups.Count - 1 & ")", False) Gesamtanzahl = regexMatch.Groups.Count - 1 For y = 1 To regexMatch.Groups.Count - 1 Dim g As Group = regexMatch.Groups(y) g.ToString() Next Dim i As Integer For i = 1 To regexMatch.Groups.Count - 1 Dim g As Group = regexMatch.Groups(i) ' Dim cc As CaptureCollection = g.Captures ' Dim j As Integer ' For j = 0 To cc.Count - 1 ' Dim c As Capture = cc(j) ' MsgBox("Capture" & j & "='" & c.ToString() _ '& "', Position=" & c.Index) ' Next Console.WriteLine("Group" & i & "='" & g.ToString() & "'") If Pos_From = 0 And Gesamtanzahl = 1 Then 'Das Ende ist erreicht - Ausstieg ReDim Preserve Ergebnis(0) Ergebnis(0) = Convert.ToString(g.ToString) Exit_For = True Exit For End If If Pos_From <> 10000 Then If Pos_To <> 0 And Pos_From >= Pos_From Then ' den übergebenen/gefundenen IndexWert, eintragen ReDim Preserve Ergebnis(Gesamtanzahl - 1) Ergebnis(Gesamtanzahl - 1) = Convert.ToString(g.ToString) 'Das Ende ist erreicht - Ausstieg If Pos_To = Gesamtanzahl Then Exit_For = True End If Else 'Es gibt nur From, also auch nur einen Wert If Pos_From = Gesamtanzahl Then 'Das Ende ist erreicht - Ausstieg ReDim Preserve Ergebnis(0) Ergebnis(0) = Convert.ToString(g.ToString) Exit_For = True End If End If Else ReDim Preserve Ergebnis(Gesamtanzahl - 1) ' den übergebenen/gefundenen IndexWert, eintragen Ergebnis(Gesamtanzahl - 1) = Convert.ToString(g.ToString) End If If Exit_For = True Then Exit For End If ' Dim cc As CaptureCollection = g.Captures ' Dim j As Integer ' For j = 0 To cc.Count - 1 ' Dim c As Capture = cc(j) ' MsgBox("Capture" & j & "='" & c.ToString() _ '& "', Position=" & c.Index) ' Console.WriteLine("Capture" & j & "='" & c.ToString() _ '& "', Position=" & c.Index) ' Next Next regexMatch = regexMatch.NextMatch() Else If My.Settings.vLogErrorsonly = False Then ClassLoggerNI.Add(" >> Using Matchelements.....", False) For Each element As System.Text.RegularExpressions.Match In elemente element.ToString() Next For Each element As System.Text.RegularExpressions.Match In elemente Gesamtanzahl += 1 'MsgBox(element.ToString) 'filling the row with values. Item property is used to set the field value. If Pos_From <> 10000 Then If Pos_To <> 0 And Pos_From >= Pos_From Then ' den übergebenen/gefundenen IndexWert, eintragen ReDim Preserve Ergebnis(Gesamtanzahl - 1) Ergebnis(Gesamtanzahl - 1) = Convert.ToString(element.ToString) 'Das Ende ist erreicht - Ausstieg If Pos_To = Gesamtanzahl Then Exit_For = True End If Else 'Es gibt nur From, also auch nur einen Wert If Pos_From = Gesamtanzahl Then 'Das Ende ist erreicht - Ausstieg ReDim Preserve Ergebnis(0) Ergebnis(0) = Convert.ToString(element.ToString) Exit_For = True End If End If Else ReDim Preserve Ergebnis(Gesamtanzahl - 1) ' den übergebenen/gefundenen IndexWert, eintragen Ergebnis(Gesamtanzahl - 1) = Convert.ToString(element.ToString) End If If Exit_For = True Then Exit For End If Next ' zum nächsten Vorkommen End If End If If Gesamtanzahl > 0 Then If Ergebnis.Length >= 1 Then Return Ergebnis Else ClassLoggerNI.Add(">> ACHTUNG: Array-Ergebnis Length = 0", False) Return Nothing End If Else ClassLoggerNI.Add(">> ACHTUNG: Keine Vorkommen für diese Regular Expression gefunden", False) Return Nothing End If Return Ergebnis Catch ex As Exception ClassLoggerNI.Add("## Fehler in GetValuesFromFulltext: " & ex.Message, False) Return Nothing End Try End Function End Class