1
This commit is contained in:
@@ -1622,11 +1622,19 @@ public class JDUtil {
|
|||||||
*/
|
*/
|
||||||
public static List<String> extractUJDUrls(String message) {
|
public static List<String> extractUJDUrls(String message) {
|
||||||
List<String> urls = new ArrayList<>();
|
List<String> urls = new ArrayList<>();
|
||||||
Pattern pattern = Pattern.compile("https://u\\.jd\\.com/\\S+");
|
// 支持两类链接:
|
||||||
|
// 1) u.jd.com 短链
|
||||||
|
// 2) jingfen.jd.com/detail/<token>.html(协议可选)
|
||||||
|
Pattern pattern = Pattern.compile("(?:https?://)?(?:u\\.jd\\.com/\\S+|jingfen\\.jd\\.com/detail/[^\\s]+\\.html)");
|
||||||
Matcher matcher = pattern.matcher(message);
|
Matcher matcher = pattern.matcher(message);
|
||||||
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
urls.add(matcher.group());
|
String found = matcher.group();
|
||||||
|
// 规范化:缺省协议时补全为 https://
|
||||||
|
if (!found.startsWith("http")) {
|
||||||
|
found = "https://" + found;
|
||||||
|
}
|
||||||
|
urls.add(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
|
|||||||
Reference in New Issue
Block a user