-4

単純なタグのスタイル属性を解析して、<font>単純なhtml属性に変換しようとしていました。たとえば、私はこの文字列を持っていて<font style="font-family:tahoma;font-size:24px;color:#9900CC;">、どういうわけかそれを<font size="24" color="#9900CC" face="tahoma">正規表現で実行できることを知っているように変換したいのですが、どうすればよいかわかりません。

ありがとう

4

1 に答える 1

0

したがって、これまでに作成した最も単純なソリューションは汚いソリューションですが、魅力のように機能します。

static public String convertCSSFonttoHTML(String css)
{

    List<List<String>> allFontTags = regexFindMultiStrings("<font[^>]*(style=['\"][^'\"]+['\"])[^>]*>", css);
    String allAttributes = "";

    for(int y=0; y<allFontTags.size(); y++)
    {
        String style = allFontTags.get(y).get(0);
        String size = regexFindString("font-size:([^0-9]+)", style);
        String color = regexFindString("color:([^;]+);", style);
        String face = regexFindString("font-family:([^;]+)", style);

        if(!size.isEmpty())
             allAttributes += "size=\""+size+"\" ";

        if(!color.isEmpty())
             allAttributes += "color=\"" + color + "\" ";

        if(!size.isEmpty())
             allAttributes += "face=\""+face+"\"";



        //do replacements to the first occurance
        css = css.replaceFirst(style, allAttributes);

        //empty atts
        allAttributes = "";
    }

    //Log.e("Regex", css);


    return css;

}
于 2012-12-15T09:15:47.170 に答える