Ver Mensaje Individual
  #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