tags:

views:

80

answers:

2

i want how to code for get only link from string using regex or anyothers.

here the following is java code:

String aas =  "window.open("+"\""+"http://www.example.com/jscript/jex5.htm"+"\""+")"+"\n"+"window.open("+"\""+"http://www.example.com/jscript/jex5.htm"+"\""+")";

how to get the link http://www.example.com/jscript/jex5.htm

thanks and advance

A: 

The Regex

(?<=window.open\(")[^"]*(?="\))

matches the link in the string you have given. Properly escaped it reads

"(?<=window.open\\(\")[^\"]*(?=\"\\))"
Jens
A: 

This will print out the first URL contained in the string that starts with "http://":

  public static void main(String[] args) throws Exception {
    String javascriptString = "window.open(" + "\"" + "http://www.example.com/jscript/jex5.htm" + "\"" + ")" + "\n" + "window.open(" + "\""
        + "http://www.example.com/jscript/jex5.htm" + "\"" + ")";

    Pattern pattern = Pattern.compile(".*(http://.*)\".*\n.*");
    Matcher m = pattern.matcher(javascriptString);

    if (m.matches()) {
      System.out.println(m.group(1));
    }
  }
Rob Heiser