<a href=http://www.baidu.com ><img src=http://localhost:8080/0.jpg width=15 height=131 style="border:1px solid #cc;padding:1px"></img></a>谁能帮忙 用java 把上面的字符串变成下面的字符串 就插了8个引号<a href="http://www.baidu.com" ><img src="http://localhost:8080/0.jpg" width="15" height="131" style="border:1px solid #cc;padding:1px"></img></a>
String str="<a href=http://www.baidu.com ><img src=http://localhost:8080/0.jpg width=15 height=131 style=\"border:1px solid #cc;padding:1px\"></img></a>";
System.out.println(str);
str=str.replaceAll("=(?!\")(.+?)(?=[\\s>])", "=\"$1\"");
System.out.println(str);
public static void main(String args[]){
String str="<a href=http://www.baidu.com ><img src=http://localhost:8080/0.jpg width=15 height=131 style=\"border:1px solid #cc;padding:1px\"></img></a>";
System.out.println(str.replaceAll("= *([a-zA-Z0-9:/\\.]+)(?=[ >])","=\"$1\""));
}
{
public static void main(String[] args)
{
String str ="<a href=http://www.baidu.com ><img src=http://localhost:8080/0.jpg width=15 height=131 style=\"border:1px solid #cc;padding:1px\"></img></a>";
Test.replaceStr(str);
}
public static String replaceStr(String str){
str =str.replaceAll("(=\\s*\")|=", "=\"").replaceAll("(\"\\s*>)|>", "\">");
System.out.println(str);
return str;
}
}