空白之才
2006-10-09 01:34:26 UTC
import java.util.regex.*;
import java.io.*;
public class Test1 {
public static void main(String[] args) throws Exception {
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new FileReader("c:/work/112.txt"));
String line="";
while( (line=br.readLine()) != null) {
sb.append(line);
}
Pattern pattern = Pattern.compile(" "); //裡面要怎麼用才能把我要的網址抽出來?
Matcher m = pattern.matcher(sb.toString());
while(m.find()) {
String str = m.group();
System.out.println(str);
}
}
}
假設在infile.txt裡面有內容如下
<a class=l href="http://www.ntnu.edu.tw/art/" onmousedown="
<a class=l href="http://203.71.53.40/" onmousedown="
<a class=l href="http://www.scdxart.com/" onmousedown="return
我只想要裡面的網址如下
http://www.ntnu.edu.tw/art/
http://203.71.53.40/
http://www.scdxart.com/
Pattern pattern = Pattern.compile(" ");
這行裡面要怎麼用
我現在只弄到這樣 但還是不對
Pattern pattern = Pattern.compile("http://[^\"\\s]+");
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.59.148.204
import java.io.*;
public class Test1 {
public static void main(String[] args) throws Exception {
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new FileReader("c:/work/112.txt"));
String line="";
while( (line=br.readLine()) != null) {
sb.append(line);
}
Pattern pattern = Pattern.compile(" "); //裡面要怎麼用才能把我要的網址抽出來?
Matcher m = pattern.matcher(sb.toString());
while(m.find()) {
String str = m.group();
System.out.println(str);
}
}
}
假設在infile.txt裡面有內容如下
<a class=l href="http://www.ntnu.edu.tw/art/" onmousedown="
<a class=l href="http://203.71.53.40/" onmousedown="
<a class=l href="http://www.scdxart.com/" onmousedown="return
我只想要裡面的網址如下
http://www.ntnu.edu.tw/art/
http://203.71.53.40/
http://www.scdxart.com/
Pattern pattern = Pattern.compile(" ");
這行裡面要怎麼用
我現在只弄到這樣 但還是不對
Pattern pattern = Pattern.compile("http://[^\"\\s]+");
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.59.148.204