【深入JAVA】正则匹配

来源:互联网 发布:什么是ai设计软件 编辑:程序博客网 时间:2024/05/21 11:18

在阅读的过程中有任何问题,欢迎一起交流

邮箱:1494713801@qq.com   

QQ:1494713801

 

◆查找html中对应条件字符串

Java代码
  1. Pattern pattern = Pattern.compile("href=\"(.+?)\"");   
  2. Matcher matcher = pattern.matcher("<a href=\"index.html\">主页</a>");   
  3. if(matcher.find()) {   
  4.   System.out.println(matcher.group(1));   
  5. }  

◆查找以name="开头、包含app的字符串

Java代码

         String pstr = "^name=\""+"(.+?)"+"app"+"(.+?)\""; 
         Pattern p = Pattern.compile(pstr); 
         Matcher m = p.matcher("name="sede.app.com.txt""); 
         if(m.find()){
            //相关处理
         }

 

参考链接:http://ipjmc.iteye.com/blog/1169491

0 0
原创粉丝点击