[英]Need a javascript regex to match a specific path
I need help to match a url that matches only if 我需要帮助才能匹配仅匹配的网址
the regex should not match if 如果正则表达式不匹配
So far i got this: 到目前为止我得到了这个:
/^http[s]?:\/\/?[^\/\s]+\/gummybear[\/]?/
examples it should be true for 它应该是真实的例子
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/
examples that it should be false for 这个例子应该是假的
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
For your specific needs, I can come up with this regex: 根据您的具体需求,我可以拿出这个正则表达式:
^https?://[^/]+/gummybear(?:/?|/?#.*)$
I haven't escaped slashes to make it more readable, but for javascript you can use: 我没有转义斜线以使其更具可读性,但对于javascript,您可以使用:
^https?:\/\/[^\/]+\/gummybear(?:\/?|\/?#.*)$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.