Javascript 正则表达式匹配基于单词的URL
我想编写一个javascript正则表达式来匹配包含单词-booker的URL 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
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]+)
这将匹配
- 带有可选
的https
- 两个前斜杠
- 类似单词的项目,或句号一次或多次
- 一次或多次使用正斜杠或单词项
一次-booker
- 一个或多个前斜杠或单词项(第二次,iNas-Bookes在中间,如果需要的话,这个选项可以被删除)。
- 一次或多次使用句号和类似单词的字符(用于文件名)
/(?=https?:\/\/[^ ]+-booker[^ ]+)(.*)/g
(?=https?:\/\/[^]*-booker[^]+)
是一个积极的前瞻-声明应该在url中找到单词-booker
你试过什么吗?从这里开始阅读正则表达式:-