我有这个Java正则表达式来匹配网址中的Facebook帖子ID:
Pattern POST_ID_PATTERN =
Pattern.compile(
"[^/|.!=](\\d{7,}(?!.*\\d{7,})\\d+)",
Pattern.CASE_INSENSITIVE
);
matcher = POST_ID_PATTERN.matcher(url);
if (matcher.find()) {
return matcher.group(1);
}
但是对于此URL https://www.facebook.com/167637636622585/posts/2607815435938114/
它给了我607815435938114
,何时应该返回2607815435938114
。
一个regex101
测试用例:https://regex101.com/r/ya4F5K/1