'/** ' * Wird bei rx_match_array verwendet ' */ Public Enum rxArrayEnum rxIncludeMatch = 2 ^ 0 'Der gefundene Gesammtstring wird mit index 0 zurückgegeben rxIncludeSubmatches = 2 ^ 1 'Die Submatches werden mit ausgegen End Enum '/** ' * Copyright mpl by ERB software | http://wiki.yaslaw.info ' * ' * Eine Erweiterung zu rx_match. Das Resultat wird als Array ausgegeben. ' * @example Set mc = rx_match("([\d\.]+)", "3 Würste unf 4.5 Liter Wasser", pfGlobal) ' * @param String Pattern analog RegExp ' * @param String Der String der bearbeitet werden soll ' * @param rxFlagsEnum Eigenschaften von Regexp. Global, IgnoreCase und Multiline. ' * Die Eigenschaften können mit + kombiniert werden ' * @param rxArrayEnum Angabe was alles ausgegeben werden soll. Die Matches/Submatches ' * Die Auswahl kann mit + kombiniert werden ' * @return MatchCollection ' */ Public Function rx_match_array( _ ByVal iPattern As String, _ ByVal iSubject As String, _ Optional ByVal iFlags As rxFlagsEnum = rxGlobal + rxIgnorCase, _ Optional ByVal iArrayFlags As rxArrayEnum = rxIncludeSubmatches _ ) As Variant() 'Dim mc As MatchCollection: Set mc = rx_match(iPattern, iSubject, iFlags) 'Dim m As Match Dim mc As Object: Set mc = rx_match(iPattern, iSubject, iFlags) Dim m As Object Dim sm() As Variant Dim retArr() As Variant Dim firstIdx As Integer Dim diffIdx As Integer Dim lastIdx As Integer Dim i, k firstIdx = IIf(iArrayFlags And rxIncludeMatch, 1, 0) diffIdx = firstIdx * -1 If iFlags And rxGlobal Then ReDim retArr(mc.count - 1) For i = 0 To mc.count - 1 Set m = mc.Item(i) lastIdx = m.SubMatches.count + firstIdx - 1 If iArrayFlags And rxIncludeSubmatches And m.SubMatches.count > 0 Then ReDim sm(lastIdx) If iArrayFlags And rxIncludeMatch Then sm(0) = m.value For k = firstIdx To lastIdx sm(k) = m.SubMatches(k + diffIdx) Next k ElseIf iArrayFlags And rxIncludeSubmatches Then If iArrayFlags And rxIncludeMatch Then ReDim sm(0): sm(0) = m.value Else Erase sm End If Else ReDim sm(0) sm(0) = m.value End If If iFlags And rxGlobal Then retArr(i) = sm Else retArr = sm End If Next i rx_match_array = retArr Set m = Nothing Set mc = Nothing End Function