JS - Regexp匹配网址中的slug(如果有的话)

时间:2016-06-03 21:20:38

标签: javascript regex

是否有任何有效/好的方法来匹配网址中的slug?

例如:

匹配:

  • http://somepage.com/s/XXXXX/this-is-slug-i-want
  • http://somepage.com/s/XXXXX/this-is-slug-i-want/
  • http://somepage.com/s/XXXXX/this-is-slug-i-want?foo=bar
  • http://somepage.com/s/XXXXX/this-is-slug-i-want#foo

不匹配:

  • http://somepage.com/s/XXXXX/somePage.html 和类似的(.php等)

2 个答案:

答案 0 :(得分:0)

这个怎么样......

http:\/\/somepage.com\/s\/XXXXX\/(?!.*\.html).*

测试:http://rubular.com/r/KyTWM1fizJ

答案 1 :(得分:0)

为什么不/^http:\/\/.+\/this-is-the-slug-i-want\/?(\?.*)?/

相关问题