日期:2014-05-18  浏览次数:20604 次

JAVA中取得与指定正则表达式相匹配的串
如题:
比如
str= " <font   size= '23 '> abc </font> ";
我要得到 <font   size= '23 '> 和 </font>


------解决方案--------------------
public static void main(String[] args) {
String inputstr = " <font size= '23 '> abc </font> ";
String str = " <[^> ]+> ";
Pattern pat = Pattern.compile(str);
Matcher mat = pat.matcher(inputstr);
StringBuffer sb = new StringBuffer();
while (mat.find()) {
sb.append(mat.group().toString());
sb.append( "\n ");
}
System.out.println(sb);
}