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?
PHP中文网2017-06-26 10:56:30
is the current page url: window.location.pathname.substr(1).split('/')
Not the current page url: url.replace(/http(s){0,1}://[^/]+//, '').split('/')
给我你的怀抱2017-06-26 10:56:30
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"]