正则表达式捕获组返回损坏的匹配项

时间:2019-04-18 00:31:19

标签: java regex

我有这个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

0 个答案:

没有答案