正则表达式 - 匹配 URL with/without 结尾的斜杠

RegEx - Match URL with/without slash at end

如何进行正则表达式匹配:

chocolate-pudding/ice-cream

chocolate-pudding/ice-cream/cake

但不匹配:

chocolate-pudding/ice-cream-foo-bar

您可以对空白字符或正斜杠字符使用正向先行。

(chocolate-pudding\/)(\w*-\w*)(?=[\s\/])(\/?\w*)

实时正则表达式 here