String strTemp="<span>1</span><img src='images/1.gif'><a href='images/1.gif'>link1</a><a href='www.sina.com'>link2</a>";
String partn="(<a\\s+href\\s*=(\\s*(\"[^\"]*\"|[^\\s>])[^>]*)>([^<]*))(.*)(</a>)";
Vector colInoput= new Vector();
Pattern pattern=Pattern.compile(partn);
Matcher matcher=pattern.matcher(strTemp);
while(matcher.find()){
colInoput.add(matcher.group(1));
}
for(int i=0;i<colInoput.size();i++){
out.println(colInoput.elementAt(i).toString()+"<hr>");
}
//////////////////////////////////
问题:我现在想把strTemp中的<a>……</a>全部取出来该怎么做?
谢谢先!
String partn="(<a\\s+href\\s*=(\\s*(\"[^\"]*\"|[^\\s>])[^>]*)>([^<]*))(.*)(</a>)";
Vector colInoput= new Vector();
Pattern pattern=Pattern.compile(partn);
Matcher matcher=pattern.matcher(strTemp);
while(matcher.find()){
colInoput.add(matcher.group(1));
}
for(int i=0;i<colInoput.size();i++){
out.println(colInoput.elementAt(i).toString()+"<hr>");
}
//////////////////////////////////
问题:我现在想把strTemp中的<a>……</a>全部取出来该怎么做?
谢谢先!
解决方案 »
- 利用spring进行数据库操作
- 如何把tomcat项目默认访问地址http://localhost:8080/HR/的最后斜杠去掉
- 急求jsp或java显示当前位置导航!!!谢谢!!!
- 求上传图片及其方法例子 jsp的
- 夜深了还在为关于jsp+tomcat+mysql数据库连接的问题头痛!请高手帮忙
- 程序运行正常,网页左下角报错如何调试解决
- struts2 标签问题
- MVC模式中的JavaBean设计问题
- 在登录窗口提交时,为何会关闭了窗口?
- 关于eclipse下发布项目到tomcat,其中项目上面有个项目名字为Servers
- 聘JSP开发工程师
- 如何将word文档写到oracle的blob字段里?又如何让客户端下载??
colInoput.add(matcher.group(3)+matcher.group(5));
}
public static void testRegex()
throws Exception
{
String content = "<span>1</span><img src='images/1.gif'><a href='images/1.gif'>link1</a><br><a href='www.sina.com'>link2</a>";
String value = null;String value2 = null;
Pattern dtPattern = Pattern.compile("<a\\s.*?>(.*?)</a>",
Pattern.CASE_INSENSITIVE);
Matcher dtMatcher = dtPattern.matcher(content);
Vector anchorVector= new Vector();
while (dtMatcher.find())
{
value = dtMatcher.group(0);
value = value.trim();
value2 = dtMatcher.group(1);
value2 = value2.trim();
anchorVector.add(value2);
System.out.println( "raw text:" + value + "-->anchor text:" + value2 );
content = content.replaceAll(value, "");
dtMatcher = dtPattern.matcher(content);
}
}
public static void testRegex()
throws Exception
{
String content = "<span>1</span><img src='images/1.gif'><a href='images/1.gif'>link1</a><br><a href='www.sina.com'>link2</a>";
String value = null;String value2 = null;
Pattern dtPattern = Pattern.compile("<a\\s.*?>(.*?)</a>",
Pattern.CASE_INSENSITIVE);
Matcher dtMatcher = dtPattern.matcher(content);
Vector anchorVector= new Vector();
while (dtMatcher.find())
{
value = dtMatcher.group(0);
value = value.trim();
value2 = dtMatcher.group(1);
value2 = value2.trim();
anchorVector.add(value2);
System.out.println( "raw text:" + value + "-->anchor text:" + value2 );
content = content.replaceAll(value, "");
dtMatcher = dtPattern.matcher(content);
}
}
"<a href='www.sina.com'>link2</a>";
//其实你就把下面的copy到你那里,别的都不用该。
String partn="(<a\\s+href\\s*=(\\s*(\"[^\"]*\"|[^\\s>])[^>]*)>([^<]*)(.*)(</a>))";
Vector colInoput= new Vector();
Pattern pattern=Pattern.compile(partn);
Matcher matcher=pattern.matcher(strTemp);
while(matcher.find()){
colInoput.add(matcher.group(1));
//colInoput.add(matcher.group());
}
for(int i=0;i<colInoput.size();i++){
System.out.println(colInoput.elementAt(i).toString()+"<hr>");
}
}