![](/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.