Foros del Web » Programando para Internet » Javascript »

Expresiones regulares

Estas en el tema de Expresiones regulares en el foro de Javascript en Foros del Web. alguien sabe como se podria extraer esta cadena entera con una expresion regular: <TR> <TD bgColor=#cccccc></TD> <TD width=1 bgColor=#cccccc></TD> <TD bgColor=#cccccc></TD> <TD width=1 bgColor=#cccccc></TD> <TD ...
  #1 (permalink)  
Antiguo 24/10/2006, 02:32
Avatar de Nombela  
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
Expresiones regulares

alguien sabe como se podria extraer esta cadena entera con una expresion regular:

<TR>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD></TR>

Quiero sacar todas las lineas que esten entre 2 <tr> pero con los TR sin atributos.

gracias

gracias
__________________
:si: El hombre es el único animal que come sin tener hambre, bebe sin tener sed y habla sin tener nada que decir. :si:
  #2 (permalink)  
Antiguo 24/10/2006, 08:58
Avatar de Nombela  
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
Seria algo asi:

*<tr>[^>](.+)</tr>.* es que no la consigo.

Queria que me sacara todo el texto que estuviera entre 2 <tr> y ke fuera entre <tr> que no tiene atributos, es decir solo <tr> no <tr name=1>.

saludos
__________________
:si: El hombre es el único animal que come sin tener hambre, bebe sin tener sed y habla sin tener nada que decir. :si:
  #3 (permalink)  
Antiguo 24/10/2006, 09:36
Avatar de Nombela  
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
algo asi parece que se acerca mas pero no consgio que sea solo el <tr> que no tiene atributos, me saca los 2 <tr> que hay.

<tr><td[^>]*>(.+)</td></tr>
__________________
:si: El hombre es el único animal que come sin tener hambre, bebe sin tener sed y habla sin tener nada que decir. :si:
  #4 (permalink)  
Antiguo 24/10/2006, 10:02
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Y algo así no te sirve:
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<script>
function tester(){
cuerpo=document.getElementById('pepe').innerHTML;
cuerpo=cuerpo.split('</TBODY>').join('');
cuerpo=cuerpo.split('</tbody>').join('');
cuerpo=cuerpo.split('<TBODY>').join('');
cuerpo=cuerpo.split('<tbody>').join('');
cuerpo=cuerpo.split('</TR>').join('');
cuerpo=cuerpo.split('</tr>').join('');
cuerpo=cuerpo.split('<TR>').join('');
cuerpo=cuerpo.split('<tr>').join('');
alert(cuerpo);
}
</script>
</head>

<body onload="tester()">
<table id="pepe">
<TR>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD></TR></table>

</body>
</html>
  #5 (permalink)  
Antiguo 24/10/2006, 10:12
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Si todavía querés hacerlo con regexp, sería así:
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<script>
function tester(){
cuerpo=document.getElementById('pepe').innerHTML;
patron=/<td[^>]+>.*<\/td>+/gi;
coincidencias=cuerpo.match(patron);
if(coincidencias.length){
for(i=0;i<coincidencias.length;i++){
alert(coincidencias[i]);
}
}
}
</script>
</head>

<body onload="tester()">
<table id="pepe">
<TR>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD>
<TD bgColor=#cccccc></TD>
<TD width=1 bgColor=#cccccc></TD></TR></table>

</body>
</html>

Última edición por Panino5001; 24/10/2006 a las 15:42
  #6 (permalink)  
Antiguo 25/10/2006, 01:19
Avatar de Nombela  
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
Veras es casi eso pero en este caso me saca todos los <TR> que tiene mi cadena donde esta el codigo html. Yo kiere me saca solo los <tr> que no tienen atributos, es decir si tengo:

<tr>
<td>pepe</td>
<td>ramon</td>
</tr>
<tr id='cosmo'>
<td>hello</td>
<td>by</td>
</tr>
<tr>
<td>sfsdf</td>
<td>dhfghfg</td>
</tr>
<tr id='luisma'>
<td>sdfsdf</td>
<td>fghfgh</td>
</tr>

kiero ke solo me saque para hacer un replace y elminarlo esta parte:

<tr>
<td>pepe</td>
<td>ramon</td>
</tr>
<tr>
<td>sfsdf</td>
<td>dhfghfg</td>
</tr>

Solo los <tr> que no tienen atributos dentro de la etiqueta.

Gracias
__________________
:si: El hombre es el único animal que come sin tener hambre, bebe sin tener sed y habla sin tener nada que decir. :si:
  #7 (permalink)  
Antiguo 26/10/2006, 01:24
Avatar de Nombela  
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
Por favore una ayuda de los expertos de espresiones regulares...
__________________
:si: El hombre es el único animal que come sin tener hambre, bebe sin tener sed y habla sin tener nada que decir. :si:
  #8 (permalink)  
Antiguo 30/10/2006, 02:19
Avatar de Nombela  
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
Insisto...
__________________
:si: El hombre es el único animal que come sin tener hambre, bebe sin tener sed y habla sin tener nada que decir. :si:
  #9 (permalink)  
Antiguo 30/10/2006, 07:18
foo
 
Fecha de Ingreso: febrero-2006
Mensajes: 278
Antigüedad: 18 años, 3 meses
Puntos: 0
seria bueno que revisaras algun tutorial de reg exps

prueba con lo siguiente
html = html.replace(/<tr\s*([^\s]+?)>.*?<\/tr>/img, "");
  #10 (permalink)  
Antiguo 30/10/2006, 07:54
Avatar de SiR.CARAJ0DIDA  
Fecha de Ingreso: junio-2004
Ubicación: Acá
Mensajes: 1.166
Antigüedad: 19 años, 10 meses
Puntos: 4
creo q se estan complicando un poquito

/<tr\s*>(.*?)</tr\s*>/i

con eso basta, creo q hay q usar el metodo exec() para capturar lo q esta entre parentesis
__________________
Internet Explorer SuckS
Download FireFox
  #11 (permalink)  
Antiguo 30/10/2006, 08:48
foo
 
Fecha de Ingreso: febrero-2006
Mensajes: 278
Antigüedad: 18 años, 3 meses
Puntos: 0
ya estoy ciego, yo crei haber leido que se tenia que sacar los tr con atributos, por eso puse eso
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:24.