Java使用正则表达式将UBB的img表达方法转换成html样式

阅读更多
//此方法用于解析将UBB的img表达方法转换成html样式,使用regx包
 
public static String convertTags(String str)
 {
   if (str == null || str.length() == 0) 
   {
    return str;
   }
   String patt = "(\\[img\\])([^\\[]+)(\\[/img\\])";
   Pattern p = Pattern.compile(patt);
   Matcher m = p.matcher(str);
   StringBuffer sb = new StringBuffer();
   int i=0;
   boolean result = m.find();
   while(result) 
   {
    i++;
    m.appendReplacement(sb, "");
    result = m.find();
   }
   m.appendTail(sb);
   return sb.toString();
  }

你可能感兴趣的:(正则表达式,HTML,Java)