【发布时间】:2015-11-22 19:54:44
【问题描述】:
我正在处理一个包含大约 1000 万个文件的语料库。有些文件的 url 中包含反斜杠 ('\')。我想替换这些文件中的所有 URL。以下工作正常,直到找到包含反斜杠的 URL。
public static String removeUrl(String str)
{
String urlPattern = "((https?|ftp|gopher|telnet|file|Unsure):((//)|(\\\\))[\\w\\d:#@%/;$~_?\\+-=\\\\\\.&]*)";
Pattern p = Pattern.compile(urlPattern, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(str);
while (str!=null && m.find()) {
str = str.replaceAll(m.group(0)," ").trim(); // ERROR is occuring here when m.group(0) has URL with '\'
}
return str;
}
有什么帮助吗?
【问题讨论】:
-
你能补充一些例子吗?
-
请在示例中告诉您所需的输出
标签: java regex replaceall