Javascript 正则表达式匹配基于单词的URL

Javascript 正则表达式匹配基于单词的URL,javascript,regex,Javascript,Regex,我想编写一个javascript正则表达式来匹配包含单词-booker的URL URL通常类似于: http://domain.local/htmlforms/mforms/product1-booker.html http://domain.local/htmlforms/mforms/product2-booker.html http://domain.local/htmlforms/mforms/product3.html http://domain.local/htmlforms/mfo

我想编写一个javascript正则表达式来匹配包含单词-booker的URL

URL通常类似于:

http://domain.local/htmlforms/mforms/product1-booker.html
http://domain.local/htmlforms/mforms/product2-booker.html
http://domain.local/htmlforms/mforms/product3.html
http://domain.local/htmlforms/mforms/product4.html
谢谢。

我想这会有帮助的

/\http:\/\/domain.local\/htmlforms\/mforms\/\w+-booker.html/g
这应该做到:

https?\:\/{2}[\w\.]+(\/[\w]+)+\-booker(\/[\w]+|\.[\w]+)
这将匹配

  • 带有可选
    s
    的http
  • 两个前斜杠
  • 类似单词的项目,或句号一次或多次
  • 一次或多次使用正斜杠或单词项
  • -booker
    一次
  • 一个或多个前斜杠或单词项(第二次,iNas-Bookes在中间,如果需要的话,这个选项可以被删除)。
  • 一次或多次使用句号和类似单词的字符(用于文件名)
有关示例,请参见

我希望这有帮助。

另外,请尝试:

/(?=https?:\/\/[^ ]+-booker[^ ]+)(.*)/g
(?=https?:\/\/[^]*-booker[^]+)
是一个积极的前瞻-声明应该在url中找到单词
-booker


你试过什么吗?从这里开始阅读正则表达式:-