- 需求:
- 获取一个网页上的邮箱地址
- */
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.regex.Pattern;
- import java.util.regex.Matcher;
- import java.net.URL;
- public classTest{
- public static void main(String...args)throws Exception{
- URL url =new URL("http://127.0.0.1:8080/");
- BufferedReader bufin =
- new BufferedReader(new InputStreamReader(url.openStream()));
- String line =null;
- String regex = "[1-9a-zA-z]\\w+@\\w+(\\.\\w+)+";
- Pattern p =Pattern.compile(regex);
- while((line=bufin.readLine())!=null){
- Matcher m = p.matcher(line);
- while(m.find()){
- System.out.println(m.group());
- }
- }
- }
- }
复制代码 |
|