<font face="Arial,Serif" size="+2" color="red">
拆成
face Arial,Serif
size +2
color red 我是这样拆的
import java.util.regex.*;
public class Test12{
 public static void main(String args[]){
    String a="<font face=\"Arial,Serif\" size=\"+2\" color=\"red\">";
    String s[]=a.split("<|>|\\\"|=|font");
   
    System.out.println(s[2]+s[3]+"\t"+s[4]);
    System.out.println(s[5]+"\t"+s[7]);
    System.out.println(s[8]+"\t"+s[10]);
 }
}貌似有点取巧了,请高手给的正规的写法,谢谢

解决方案 »

  1.   

    <font face="Arial,Serif" size="+2" color="red">待拆的字符串仅仅是这样的?
      

  2.   


    public static void main(String[] args) {
    String str="<font face=\"Arial,Serif\" size=\"+2\" color=\"red\">";
    for(String s :str.split("[\\s<>\\\"&&[^=\\\"]]")){
    if(s.contains("=")){
    s = s.replaceFirst("=\\\"", " ");
    s = s.substring(0, s.length()-1);
    System.out.println(s);
    }
    }
    }
      

  3.   

    LZ看看这个,是不是符合你的要求public static void main(String[] s)
    {

    StringBuilder sb = new StringBuilder("<font face=\"Arial,Serif\" size=\"+2\" color=\"red\">"); Pattern p = Pattern.compile("<\\s*\\w+(\\s+([\\w]+\\s*)=\"([^\"]*)\")*?\\s*>");

    Matcher m = p.matcher(sb.toString());

    while(m.find())
    {
    if(m.group(2) == null || m.group(3) == null)
    break;
    System.out.print(m.group(2)+" ");
    System.out.println(m.group(3));
    int start = sb.indexOf(m.group(1));
    int end = start + m.group(1).length();
    sb.delete(start, end);
    m = p.matcher(sb.toString());
    }
    }
      

  4.   

    这样吧,=号两边都可以有空格的
    Pattern p = Pattern.compile("<\\s*\\w+(\\s+([\\w]+\\s*)=\\s*\"([^\"]*)\")*?\\s*>");
      

  5.   

    htmlparser一个专门处理HTML文件的处理程序包