我需要幫助,以匹配匹配只有需要一個javascript正則表達式來匹配特定的路徑
- 路徑是否完全匹配/ gummybear /或/ gummybear(情況sensetive)
- 的協議是HTTP網址或https
- 域/主機/端口/散列可以是任何東西
正則表達式不應該比賽如果
- 的路徑是/ gummybear/foobar的
- 它包含搜索參數,如查詢=字符串
到目前爲止,我得到這個:
/^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://example.com:81/gummybear/#/exaple/1234/ '和你的「不應該匹配」'路徑是/ gummybear/foobar'? –
@FedericoPiazza它匹配另一個子目錄 – Endless