正则替换域名

import java.util.regex.*;

public class Test {

public static void main(String[] args) {
System.out.println(doHref("

11111

"));
}

public static String doFilter(String input) {

Pattern p = Pattern
.compile(
"(<\\s*(?:\\/)?\\s*(?:(?:a)|(?:br)|(?:img))\\s*[^<>]*>)|(<\\s*(?:\\/)?\\s*[^<>]*>)|([^><]+)",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
Matcher m = p.matcher(input);
StringBuffer buff = new StringBuffer("");
while (m.find()) {
if (null != m.group(1)) {
buff.append(m.group(1));
} else {
if (null != m.group(2)) {
continue;
} else {
if (null != m.group(3)) {
buff.append(m.group(3));
}
}
}
}
return buff.toString();
}

public static String doHref(String input) {
//return input.replaceAll("((?:http(?:s)?://)|(?:www.)[^\\s]+)","$1");
return input.replaceAll("http://[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}(\\:[0-9]{4}){0,1}/DownloadServlet",
"/DownloadServlet");
}

}

你可能感兴趣的:(正则替换域名)