当前位置: 代码迷 >> Java Web开发 >> JAVA中取得与指定正则表达式相匹配的串,该怎么处理
  详细解决方案

JAVA中取得与指定正则表达式相匹配的串,该怎么处理

热度:67   发布时间:2016-04-17 15:26:26.0
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);
}
  相关解决方案