這是一個簡單的問題,但我只是不明白。 我想檢測一個字符串中的網址,並用縮短的網址替換它們。檢測並從字符串中提取網址?
我發現從計算器這個表達式,但結果卻http
Pattern p = Pattern.compile("\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(str);
boolean result = m.find();
while (result) {
for (int i = 1; i <= m.groupCount(); i++) {
String url=m.group(i);
str = str.replace(url, shorten(url));
}
result = m.find();
}
return html;
有沒有更好的主意嗎?
氏即使對於尾隨逗號和空格也是如此。Great – 2016-08-22 08:46:19