miércoles, 7 de noviembre de 2018

regex matches to array

Dim matches As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
     
Dim matches() As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Cast(Of System.Text.RegularExpressions.Match)().ToArray

 For Each m As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
            MsgBox(m.Value)
        Next


Otro ejemplo
Dim lista_match As MatchCollection = Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
        Dim x() As String = lista_match.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray


Para extraer una sola tabla
Dim tabla_sql As String = System.Text.RegularExpressions.Regex.Match(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Value.Trim


fuente

No hay comentarios.:

Publicar un comentario