Red de conocimiento informático - Problemas con los teléfonos móviles - vb obtiene rápidamente el código fuente de una página web y extrae su contenido

vb obtiene rápidamente el código fuente de una página web y extrae su contenido

La siguiente función puede lograr lo que desea:

Función TestRegExp(ByVal myString$, ByVal myPattern$, Opcional myMark$ = "gimt", Opcional myRepString$)

If myString = " " O myPattern = "" Entonces

TestRegExp = ""

Debug.Print "Los datos no pueden estar vacíos"

Salir de la función

End If

'Crear objeto. p>

Dim objRegExp As RegExp

Dim objMatch As Match

Dim colMatches As MatchCollection

Dim RetStr As String

Establecer objRegExp = Nueva expresión regular

'Tipo regular

objRegExp.Pattern = miPatrón

'IIf(InStr(miPatrón, "s") <> 0, "", myPattern)

' Distingue entre mayúsculas y minúsculas

' p> objRegExp.IgnoreCase = IIf(InStr(LCase$(myMark), "i") > 0, Verdadero, Falso)

' ¿Es global?

objRegExp.IgnoreCase = IIf(InStr(LCase$(myMark), "i") <> 0, Verdadero, Falso)

' ¿Es global?

objRegExp.IgnoreCase = IIf(InStr(LCase$(myMark), "i") <> 0, True, False)

' ¿Es mundial? "g") > 0, True, False)

' Si se ajustan las líneas

objRegExp.MultiLine = IIf(InStr(LCase$(myMark), "m") > 0 , Verdadero, Falso)

Si objRegExp.Test( myString) Entonces

Si InStr(myMark, "r") > 0 Entonces

Debug.Print " Reemplazar"

RetStr = objRegExp.Replace(myString, myRepString)

Debug.Print IIf(RetStr <> "", "Resultado de reemplazo" & Left(RetStr, 10), "No se encontraron caracteres reemplazables ")

Else

Depurar.Imprimir "Buscando"

If InStr(myMark.Test( myString)Imprimir "Buscando"

Set colMatches = objRegExp.Execute(myString) ' Ejecuta la búsqueda

'MsgBox colMatches.Count

Para cada objMatch en colMatches ' Itera a través de la colección coincidente.

'RetStr = RetStr & objMatch.FirstIndex

RetStr = RetStr & objMatch.Value & vbCrLf

Siguiente paso

Debug.Print IIf(RetStr <> """, "Resultados de búsqueda" & Left(RetStr, 10), "No se encontraron coincidencias")

End If

Else

RetStr = ""

Debug.Print "No se encontró ninguna coincidencia, verifique si la regularización es correcta"

End If

TestRegExp = RetStr

Función final