Foros del Web » Programación para mayores de 30 ;) » Java »

Problema en Expresion Regular

Estas en el tema de Problema en Expresion Regular en el foro de Java en Foros del Web. Cree el siguiente codigo @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código java: Ver original /*  * To change this template, choose Tools | Templates  * and open the template ...
  #1 (permalink)  
Antiguo 11/12/2011, 14:20
marcofbb
Invitado
 
Mensajes: n/a
Puntos:
Problema en Expresion Regular

Cree el siguiente codigo
Código java:
Ver original
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package javaapplication1;
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. import java.net.MalformedURLException;
  10. import java.net.URL;
  11. import java.net.URLConnection;
  12. import java.util.regex.Matcher;
  13. import java.util.regex.Pattern;
  14.  
  15. /**
  16.  *
  17.  * @author Administrador
  18.  */
  19. public class JavaApplication1 {
  20.  
  21.     /**
  22.      * @param args the command line arguments
  23.      */
  24.     public static void main(String[] args)
  25.         URL url = new URL("http://www.megaupload.com/?d=44DIF7IK");
  26.         URLConnection con = url.openConnection();
  27.         BufferedReader in = new BufferedReader(
  28.                 new InputStreamReader(con.getInputStream()));
  29.         String linea;
  30.         int i=1;
  31.         linea = in.readLine();
  32.         while ((linea = in.readLine()) != null && i < 174) {
  33.               i++;
  34.         }
  35.         Pattern p = Pattern.compile("<a href=\"([^#])\"");
  36.         Matcher m = p.matcher(linea);
  37.         System.out.println(m.group(1));
  38.     }
  39. }

La variable linea queda con esto:

<a href="http://www1302.megaupload.com/files/95ac04563ae9e5e8d17c317fd1cd2291/Hous803.mp4" class="download_regular_usual" onclick="javascript:window.open('http://s.megaclick.com/ad.code?de=cc56cc9f-402821bf-b4593bef-319dfc3c-23f5b-3-1b943&tm=1323634368.87706&du=aHR0cDovL2FmZi5yaW5nd G9uZXBhcnRuZXIuY29tL2dlby9wcmVzZXQvMzcwMy8xLzEzNjA vMC8%3d%0a','popunder','width=800,height=800,scrol lbars=yes,status=no,resizable=yes, toolbar=no'); window.focus();" style="display:none;" id="dlbutton"></a>


Yo necesito sacar esto: http://www1302.megaupload.com/files/...91/Hous803.mp4


Pero tengo un problema en

Pattern p = Pattern.compile("<a href=\"([^#])\"");
Matcher m = p.matcher(linea);
System.out.println(m.group(1));


Me da el siguiente error:


run:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:468)
at javaapplication1.JavaApplication1.main(JavaApplica tion1.java:38)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)



¿Alguien sabe como puedo solucionarlo?

PD: Es la primera vez que uso java
  #2 (permalink)  
Antiguo 11/12/2011, 15:25
marcofbb
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Problema en Expresion Regular

Ya lo pude resolver gracias a SERBice

Código Javascript:
Ver original
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package javaapplication1;
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. import java.net.MalformedURLException;
  10. import java.net.URL;
  11. import java.net.URLConnection;
  12.  
  13. /**
  14.  *
  15.  * @author Administrador
  16.  */
  17. public class JavaApplication1 {
  18.  
  19.     /**
  20.      * @param args the command line arguments
  21.      */
  22.     public static void main(String[] args)
  23.       throws MalformedURLException, IOException {
  24.         URL url = new URL("http://www.megaupload.com/?d=44DIF7IK");
  25.         URLConnection con = url.openConnection();
  26.         BufferedReader in = new BufferedReader(
  27.                 new InputStreamReader(con.getInputStream()));
  28.         String linea;
  29.         int i=1;
  30.         linea = in.readLine();
  31.         while ((linea = in.readLine()) != null && i < 174) {
  32.               i++;
  33.         }
  34.         int j = 0;
  35.         String [] campos = linea.split("\"");  
  36.         System.out.println(campos[1]);  
  37.     }
  38. }

Etiquetas: expresion, regular, string
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 16:22.