java 正则表达

hexudonghot 2011-10-31 04:32:17
java 正则表达式 怎么 匹配 #
...全文
163 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
abc20100414 2011-11-02
  • 打赏
  • 举报
回复
学习哈
fengnenglu 2011-11-02
  • 打赏
  • 举报
回复
你试试这样写:


private final static String regxpForHrefTagSrcAttrib = ".*href=[\'\"]([\\w\\d\\.:/?=&;-[#]]*)[\'\"]";
hexudonghot 2011-11-01
  • 打赏
  • 举报
回复
public class test {

public static void main(String args[]) {

String str = "<a class=\"page-next\" href=\"http://list.tmall.com/search_product.htm?navlog=1&nav=spu-cat&spm=3.97995.146926.81&TBG=97995.146926.81&style=g&sort=d&n=40&s=40&cat=50038235#J_Filter\"";
System.out.println(str.substring(0,7));
String s1 = HtmlRegexp.findHrefUrl(str);
System.out.println(s1);
int i = s1.indexOf("?");
System.out.println(s1.substring(0, i));
}
}
---------------------------------------------------------------------------------
public static String findHrefUrl(String str) {
String regxp = regxpForHrefTagSrcAttrib;
Pattern pattern = Pattern.compile(regxp);
Matcher matcher = pattern.matcher(str);
String result = "";
while( matcher.find()){
result = matcher.group();
int i = result.indexOf("\"");
if (i == -1){
String[] asStr = result.split("\'");
return asStr[1];
} else {
String[] asStr = result.split("\"");
return asStr[1];
}
}
return null;
}
------------------------------------
private final static String regxpForHrefTagSrcAttrib = "href=[\'\"]([\\w\\d\\.:/?=&;-[#]]*)[\'\"]"; // 找出Href标签的SRC属性
fengnenglu 2011-10-31
  • 打赏
  • 举报
回复
就是#号啊!你是不是别的地方写错了

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧