String str = "<b>两跳决定冠军</b>";
Pattern p = Pattern.compile("<(.*?)>", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(str);
if (m.find())
System.out.println(m.groupCount());
如上述的代码,<(.*?)>匹配标签数,但是打印出来是1而不是2,怎么样可以计算出其中的标签数呢?匹配不对还是groupCount()有问题?
Pattern p = Pattern.compile("<(.*?)>", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(str);
if (m.find())
System.out.println(m.groupCount());
如上述的代码,<(.*?)>匹配标签数,但是打印出来是1而不是2,怎么样可以计算出其中的标签数呢?匹配不对还是groupCount()有问题?
解决方案 »
- 应届生求职,请前辈指点
- 在Servlet中增加一个进程?
- JAVA中怎么动态加载标签和文本域?
- 新人新苦恼 岁末问答题
- 急急急--关于SmartUpload上传类型的问题!在线等!!!
- 初学者在线拜师请教!!!!!!!!!!!!!!!
- 请问<jsp:useBean id="Message" scope="page" class="aq.tt"/>tt的类是怎么生成的?请网上的大侠送点及时雨,小弟在线等待
- apache+tomcat集群后button提交表单session失效奇怪问题
- 关于Bootstrap FileInput样式问题
- 关于404问题,有截图,希望大家指出错误,一直调试,还是没有找到原因,下面是代码!感谢!
- session.getAttribute在windows里能得到为什么到linux上就不行?
- <jsp:useBean id="" class="" /
Pattern p = Pattern.compile("<(.*?)>", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(str);
int i=0;
while (m.find()) ++i;
System.out.println(i+"次");