Autor
|
Tema: ayudita expresion regular (Leído 13,019 veces)
|
Psyke1
Wiki
Desconectado
Mensajes: 1.089
|
Jajajajajajajajaja Debug.Print te lo imprime en una ventana llamada Inmediato (esta abajo) cuando lo ejecutas.  No obstante puedes cambiar el Debug.Print por MsgBox si lo deseas. DoEvents! 
|
|
|
En línea
|
|
|
|
viher
Desconectado
Mensajes: 113
|
hice las siguiente modificaciones pero no me devuelve ningún valor Option Explicit Public Function Get_Text(ByVal sText As String) As Collection Const sPatern As String = "\<div class\=""col_titulo col_superior"" \>\s*(.+)\s*\<\/div\>" Dim cTemp As New Collection Dim oRegExp As Object Dim oMatch As Object Dim oMatches As Object Dim Q As Long Set oRegExp = CreateObject("VBScript.RegExp") With oRegExp .Pattern = sPatern .Global = True .IgnoreCase = True End With Set oMatches = oRegExp.Execute(sText) For Q = 0 To oMatches.Count - 1 Set oMatch = oMatches(Q) cTemp.Add oMatch.SubMatches(0) Next Q Set Get_Text = cTemp End Function 'Sub que extrae las direccións url : Http, Ftp y Https _ de un archivo utilizando una expresión regular ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub Extraer_Url(url_Path As String, Expresion As String) 'Variables para usar RegExp Dim o_RegExp As RegExp Dim o_Match As Match Dim o_Matches As MatchCollection 'Variables Fso para abrir y leer el archivo en la variable contenido Dim Contenido As String 'Lee el contenido del fichero y lo almacena en la var Contenido = Text2.Text 'crea nuevo objeto RegExp Set o_RegExp = New RegExp ' Para que no distinga mayúsculas de minúsculas o_RegExp.IgnoreCase = True o_RegExp.Global = True ' A la propiedad Pattern se le pasa la Expresión regular o_RegExp.Pattern = Expresion 'Ejecuta y busca Set o_Matches = o_RegExp.Execute(Contenido) ' Recorre en la colección For Each o_Match In o_Matches 'Agrega las url al control List List1.AddItem Replace(o_Match.Value, Chr(34), vbNullString) Next End Sub Private Sub Command1_Click() Dim Expresion As String ' Expresión regular Expresion = "\<div class\=\""col_titulo col_superior\""\>(.+)\<\/div\>" Call Extraer_Url(Text2.Text, Expresion) Text1.Text = List1.List(0) List1.Clear End Sub Private Sub Command2_Click() Text2.Text = WebBrowser1.Document.documentElement.innerHTML End Sub Private Sub Command3_Click() Dim vItem As Variant Dim S As String S = Text1.Text For Each vItem In Get_Text(S) Text3.Text = vItem Next vItem End Sub Private Sub Form_Load() WebBrowser1.Navigate ("http://www.rinconjuegos.com/just-jhon/") Me.Caption = " Ejemplo que utiliza expresiones regulares" _ & " Para extraer los enlaces de un archivo" Command1.Caption = " Abrir archivo y Extraer " End Sub
|
|
|
En línea
|
|
|
|
Psyke1
Wiki
Desconectado
Mensajes: 1.089
|
. Si solo necesitas una extracción haz asi: Option Explicit Public Function Get_Text(ByVal sText As String) As String Const sPatern As String = "\<div class\=""col_titulo col_superior"" \>\s*(.+)\s*\<\/div\>" Dim oRegExp As Object Dim oMatch As Object Dim oMatches As Object Set oRegExp = CreateObject("VBScript.RegExp") With oRegExp .Pattern = sPatern .Global = True .IgnoreCase = True End With Set oMatches = oRegExp.Execute(sText) Set oMatch = oMatches(0) Get_Text = oMatch.SubMatches(0) End Function Private Sub Form_Load() Dim S As String S = "<div class=""col_titulo col_superior"" > ¡Vivan las ranas! </div>" MsgBox Get_Text(S) End Sub
Personalmente ya no te voy a ayudar mas en este hilo, te estamos haciendo los deberes de una manera exagerada.  Creo que debes estudiar mucho, tienes algunos errores muy basicos.  Si te fijas, con las funciones que te di y un poco de sentido comun, no te deberia de costar hacerlo.  DoEvents! 
|
|
|
En línea
|
|
|
|
viher
Desconectado
Mensajes: 113
|
vale,solo una cosilla mas,lo que me devuelve tu code es "vivan las ranas",pero yo quiero que me devuelva lo que hay escrito en el Text1.Text y hago lo siguiente: Dim S As String S = Text1.Text MsgBox Get_Text(S)
pero me da error,porque? gracias!
|
|
|
En línea
|
|
|
|
raul338
Desconectado
Mensajes: 2.633
La sonrisa es la mejor forma de afrontar las cosas
|
Hay algo mal, por ahi no es la expresion regular que necesitas EDIT: For Each o_Match In o_Matches 'Agrega las url al control List List1.AddItem Replace(o_Match.Value, Chr(34), vbNullString) Next
Deberías cambiarlo por esto For Each o_Match In o_Matches 'Agrega las url al control List List1.AddItem Replace(o_Match.SubMatches(0), Chr(34), vbNullString) Next
Porque es como te dije, debes obtener los submatches, no los matches en si
|
|
« Última modificación: 30 Octubre 2010, 17:17 pm por raul338 »
|
En línea
|
|
|
|
viher
Desconectado
Mensajes: 113
|
Hay algo mal, por ahi no es la expresion regular que necesitas EDIT: For Each o_Match In o_Matches 'Agrega las url al control List List1.AddItem Replace(o_Match.Value, Chr(34), vbNullString) Next
Deberías cambiarlo por esto For Each o_Match In o_Matches 'Agrega las url al control List List1.AddItem Replace(oMatch.SubMatches(0), Chr(34), vbNullString) Next
Porque es como te dije, debes obtener los submatches, no los matches en si Variable no definida 
|
|
« Última modificación: 30 Octubre 2010, 17:16 pm por viher »
|
En línea
|
|
|
|
raul338
Desconectado
Mensajes: 2.633
La sonrisa es la mejor forma de afrontar las cosas
|
viher fijate las variables o_Match, o_Matches, y o_RegExp .... cambiales el nombre  en este pequeño tipo de cosas las deberias hacer por ti mismo Aunque el fallo fue mio, deberias darte cuenta
|
|
|
En línea
|
|
|
|
viher
Desconectado
Mensajes: 113
|
viher fijate las variables o_Match, o_Matches, y o_RegExp .... cambiales el nombre  en este pequeño tipo de cosas las deberias hacer por ti mismo Aunque el fallo fue mio, deberias darte cuenta gracias raul338,ya lo conseguí 
|
|
|
En línea
|
|
|
|
Psyke1
Wiki
Desconectado
Mensajes: 1.089
|
viher fijate las variables o_Match, o_Matches, y o_RegExp .... cambiales el nombre  en este pequeño tipo de cosas las deberias hacer por ti mismo Aunque el fallo fue mio, deberias darte cuenta gracias raul338,ya lo conseguí  hallelujah  DoEvents! 
|
|
|
En línea
|
|
|
|
viher
Desconectado
Mensajes: 113
|
alguien me puede pasar algún tutorial para aprender Regexp?? ya que he estado mirando y no he encontrado ninguno para VB6. Gracias!
|
|
|
En línea
|
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
Ayuda con Expresión Regular
Desarrollo Web
|
Shell Root
|
4
|
4,518
|
10 Abril 2011, 22:26 pm
por Shell Root
|
|
|
Aplicar expresión regular en el resultado de un curl
PHP
|
Servia
|
3
|
3,730
|
28 Agosto 2011, 14:11 pm
por WHK
|
|
|
ayuda con una expresion regular :(
Programación General
|
Elemental Code
|
6
|
4,926
|
23 Mayo 2012, 04:10 am
por Elemental Code
|
|
|
duda sobre patron de expresion regular
Programación General
|
MagnusIvanovich
|
5
|
3,585
|
14 Marzo 2013, 20:11 pm
por 1mpuls0
|
|
|
Ayuda Expresion Regular
Ingeniería Inversa
|
macmaikel
|
2
|
2,743
|
11 Junio 2013, 03:36 am
por macmaikel
|
|