62,621
社区成员
发帖
与我相关
我的任务
分享public static void main(String args[]) throws Exception{
//String str="12×(-3+12)-9/-2";
//System.out.println(Arrays.toString(str.split("(?=[+×/()-])|((?<=[+×/()-])(?<![+×/(-]{2}))")));
String regex="(<a[^>]*href=\")(?!\\w+://)(www\\.)*";
String str="<a href=\"something.html\">something</a> \n"
+"<a href=\"http://www.domain.com/something.html\">something </a>\n"
+"<a href=\"ftp://www.domain.com/something.html\">something </a>\n"
+"<a href=\"www.something.html\">something</a>";
String result = str.replaceAll(regex,"$1http://www.");
System.out.println(result);
}public class Test{
public static void main(String args[]) throws Exception{
String regex="(<a[^>]*href=\")(?!\\w+://)(www)*";
String str="<a href=\"something.html\">something</a> \n"
+"<a href=\"http://www.domain.com/something.html\">something </a>\n"
+"<a href=\"ftp://www.domain.com/something.html\">something </a>\n"
+"<a href=\"www.something.html\">something</a>";
String result = str.replaceAll(regex,"$1http://www");
System.out.println(result);
}
}
import java.util.regex.*;
//<a href="something.html">something </a>
//<a href="http://www.domain.com/something.html">something </a>
public class Test66
{
public static void main(String... args) {
StringBuilder sb = new StringBuilder();
sb.append("<a href=\"http://www.domain.com/");
String str = "<a href=\"something.html\">something </a>";
Matcher m = Pattern.compile("<a href=\"(.*?)\">(.*?)</a>").matcher(str);
while(m.find()) {
sb.append(m.group(1));
sb.append(">");
sb.append(m.group(2));
sb.append("</a>");
}
System.out.println(sb.toString());
}
}
String s1 = "<a href=\"something.html\">something </a>";
String s2 = s1.replaceAll("href=\"", "href=\"http://www.domain.com/");
System.out.println(s2);