Regular expression - javascript regular expression to list strings in links
世界只因有你
世界只因有你 2017-06-26 10:54:30
0
3
957

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

Find the characters after each / in the link and put them into an array, such as: ['one','two','three','four']
There is no limit on link length.
How to write regular expression?

世界只因有你
世界只因有你

reply all(3)
Ty80

is the current page url: window.location.pathname.substr(1).split('/')

Not the current page url: url.replace(/http(s){0,1}://[^/]+//, '').split('/')

淡淡烟草味

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

给我你的怀抱

The idea upstairs is good, remove the host in front, and use / to divide the rest, which is simpler

------Here are the answers

This requires the use of assertions

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"]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!