String content = "<a href="URL" rel="external nofollow" >";
String pattern= "href="([^" rel="external nofollow" ]*)"";
Pattern p = Pattern.compile(pattern, 2 | Pattern.DOTALL);
Matcher m = p.matcher(content);
if(m.find()) {
System.out.println("url="+m.group(1));
}
package com.gong.example;
import Java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Simple {
public static void main(String[] args){
String input="<a style=" " href = "http://www.1sucai.cn" target="_blank" >www.1sucai.cn</a>" +
"<a href = 'http://www.163.com' target='_blank' >www.163.com</a> " +
"<a href=http://www.yahoo.com target=_blank >www.yahoo.com</a>";
String patternString = "\s*(?i)href\s*=\s*("([^"]*")|'[^']*'|([^'">\s]+))"; //href
Pattern pattern = Pattern.compile(patternString,
Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
String link=matcher.group();
System.out.println(link);
link=link.replaceAll("href\s*=\s*(['|"]*)", "");
System.out.println("--"+link);
link=link.replaceAll("['|"]", "");
System.out.println("---"+link);
}
}
}
/*
功能说明:分析字符串s,提取s里面的超链接和链接文字
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegTest
{
public static void main(String[] args)
{
//String s="<p id=km> <a href=http://down.yourweb.com>空间</a> | <a ";
String s="</p><p style=height:14px><a href=http://mb.yourweb.com>企业推广</a> | <a href=http://code.yourweb.com>搜索风云榜</a> | <a href=/home.html>关于百度</a> | <a href=http://www.yourweb.com>About Baidu</a></p><p id=b>©2008 Baidu <a href=http://www.yourweb.com>使用百度前必读</a> <a href=http://www.miibeian.gov.cn target=_blank>京ICP证03xxxx号</a> <a href=http://www.1sucai.cn><img src=/get_pic/2013/11/22/20131122031447947.gif></a></p></center></body></html><!--543ff95f18f36b11-->";
String regex="<a.*?/a>";
//String regex = "<a.*>(.*)</a>";
Pattern pt=Pattern.compile(regex);
Matcher mt=pt.matcher(s);
while(mt.find())
{
System.out.println(mt.group());
System.out.println();
String s2=">.*?</a>";//标题部分
String s3="href=.*?>";
Pattern pt2=Pattern.compile(s2);
Matcher mt2=pt2.matcher(mt.group());
while(mt2.find())
{
System.out.println("标题:"+mt2.group().replaceAll(">|</a>",""));
}
Pattern pt3=Pattern.compile(s3);
Matcher mt3=pt3.matcher(mt.group());
while(mt3.find())
{
System.out.println("网址:"+mt3.group().replaceAll("href=|>",""));
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有