![](/img/trans.png)
[英]I need to match a certain part of url path using Regex and Javascript
[英]Need a javascript regex to match a specific path
我需要帮助才能匹配仅匹配的网址
如果正则表达式不匹配
到目前为止我得到了这个:
/^http[s]?:\/\/?[^\/\s]+\/gummybear[\/]?/
它应该是真实的例子
https://www.example.com:81/gummybear/
http://www.example.com/gummybear#top
https://example.com:81/gummybear#/foobar/?search=params
http://www.exa.mple.com:81/gummybear
https://example.com:81/gummybear/#/exaple/1234/
这个例子应该是假的
https://www.example.com:81/foo/gummybear/
https://www.example.com:81/guMmybear/
https://www.example.com:81/gummybear.html
http://www.example.com/gummybear/apple#top
file://example.com:81/gummybear#/foobar/?search=params
http://www.exa.mple.com:81/gummybear?search=apple#lol
https://example.com:81/#/gummybear/
http://www.test.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=value#top
根据您的具体需求,我可以拿出这个正则表达式:
^https?://[^/]+/gummybear(?:/?|/?#.*)$
我没有转义斜线以使其更具可读性,但对于javascript,您可以使用:
^https?:\/\/[^\/]+\/gummybear(?:\/?|\/?#.*)$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.