成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

正則表達(dá)式 - javascript正則列出鏈接中的字符串

瀏覽:79日期:2023-05-29 16:34:49

問題描述

http://www.xxx.com/one/two/three/four

將鏈接中每個(gè) / 后面的字符查找出來,放到一個(gè)數(shù)組里,如: [’one’,’two’,’three’,’four’] 鏈接長(zhǎng)度不限制。正則該怎么寫?

問題解答

回答1:

是當(dāng)前頁面url: window.location.pathname.substr(1).split(’/’)

不是當(dāng)前頁面url:url.replace(/http(s){0,1}://[^/]+//, ’’).split(’/’)

回答2:

window.location.pathname.split(’/’)

回答3:

樓上的思路不錯(cuò),把前面的host去掉, 剩下的用/進(jìn)行分割,更簡(jiǎn)單一點(diǎn)

-------以下是答案

這個(gè)需要用到斷言

const str = ’http://www.xxx.com/one/two/three/four’;const result = str.match(/(?/[/])w+/g).map((item) => { return item.substr(1);});// 輸出// ['www', 'one', 'two', 'three', 'four']

標(biāo)簽: JavaScript
相關(guān)文章: