求提取字符串的正则表达式,大家帮忙看看 待提取的字符串:.....<td height="20" align="center">姓名</td>....如何把字符串"姓名"提取出来。即如何把字符串<td height="20" align="center">和字符串</td>之间的内容提取出来。谢谢大家了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 已得答案,对正则表达式使用分组即可String regEx = "(<td height=\"20\" align=\"center\">)(.*)(<\\/td>)"; String fileName = "dsfkjld<td height=\"20\" align=\"center\">姓名</td>eesdf"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(fileName);MatchResult matchResult = m.toMatchResult(); System.out.println(matchResult.groupCount()); System.out.println(matchResult.group()); for (int i=0; i< matchResult.groupCount();i++) { System.out.println(matchResult.group(i)); } String regEx = "(<td height=\"20\" align=\"center\">)(.*?)(<\\/td>)"; String fileName = "dsfkjld<td height=\"20\" align=\"center\">姓名1</td>eesdfdsfkjld<td height=\"20\" align=\"center\">姓名2</td>eesdf"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(fileName); while(m.find()) { //group:0-匹配的全部字符串;1-正则表达式的第一个分组;2-正则表达式的第二个分组 for (int i=0; i<=m.groupCount();i++) { System.out.println(m.group(i)); } } 想放弃5K的工资,自己创业,拥有不平凡的生活,恳请得到指点 在面版上移除容器后再加载其他容器怎么实现。。。 一个时间的问题 求助:关于netbeans生成主项目失败 简单的数据源问题...答出者得分 一道初级题目,出错信息小弟看不懂,麻烦各位前辈指教,感激不尽!! java 环境变量在WINDOWS-XP中怎么设置 技术问题也是数学问题,高手们看看喽,谢啦。 请问各位大虾 如何将System.in.read()方法接收的数字Unicode码转为数字? main中的参数可以随便写吗? 文件读写问题:一个令我困惑的问题 有一道题,大家谁能帮我分析分析呀?谢谢了!
String regEx = "(<td height=\"20\" align=\"center\">)(.*)(<\\/td>)";
String fileName = "dsfkjld<td height=\"20\" align=\"center\">姓名</td>eesdf";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(fileName);
MatchResult matchResult = m.toMatchResult();
System.out.println(matchResult.groupCount());
System.out.println(matchResult.group());
for (int i=0; i< matchResult.groupCount();i++) {
System.out.println(matchResult.group(i));
}
String fileName = "dsfkjld<td height=\"20\" align=\"center\">姓名1</td>eesdfdsfkjld<td height=\"20\" align=\"center\">姓名2</td>eesdf";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(fileName);
while(m.find()) {
//group:0-匹配的全部字符串;1-正则表达式的第一个分组;2-正则表达式的第二个分组
for (int i=0; i<=m.groupCount();i++) {
System.out.println(m.group(i));
}
}