文章详情页
正则表达式 - javascript正则列出链接中的字符串
浏览:163日期:2023-05-29 16:34:49
问题描述
http://www.xxx.com/one/two/three/four
将链接中每个 / 后面的字符查找出来,放到一个数组里,如: [’one’,’two’,’three’,’four’] 链接长度不限制。正则该怎么写?
问题解答
回答1:是当前页面url: window.location.pathname.substr(1).split(’/’)
不是当前页面url:url.replace(/http(s){0,1}://[^/]+//, ’’).split(’/’)
回答2:window.location.pathname.split(’/’)
回答3:楼上的思路不错,把前面的host去掉, 剩下的用/进行分割,更简单一点
-------以下是答案
这个需要用到断言
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']
标签:
JavaScript
相关文章:
1. mac连接阿里云docker集群,已经卡了2天了,求问?2. debian - docker依赖的aufs-tools源码哪里可以找到啊?3. 百度地图api - Android 百度地图 集成了定位,导航 相互的jar包有冲突?4. vim - docker中新的ubuntu12.04镜像,运行vi提示,找不到命名.5. docker-compose 为何找不到配置文件?6. docker网络端口映射,没有方便点的操作方法么?7. 为什么我ping不通我的docker容器呢???8. golang - 用IDE看docker源码时的小问题9. html5和Flash对抗是什么情况?10. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?
排行榜

网公网安备