node.js - 从问号中剪切网址
问题描述
我从 IPB 论坛阅读了新主题,当我想要获取主题链接时,我得到了这个结果:
http://1234.23123/forum/topic/2-rgewgreg/?do=findComment&comment=2
如何从网址中删除这个?do=findComment&comment=2 ?它是动态的,所以如果它识别出问号然后删除其余的 url 和问号会很好。
解决方案
你不需要使用正则表达式,你可以使用
let id = "http://1234.23123/forum/topic/2-rgewgreg/?do=findComment&comment=2";
let removeStr = id.substr(id.indexOf('?'));
console.log(id.split(removeStr)[0]);
输出 :http://1234.23123/forum/topic/2-rgewgreg/
推荐阅读
- postgresql - 如何在 Ubuntu 18.04 中重启 PostgreSQL
- python - 为什么代码在 Jupyter 中有效而在 Spyder 中无效?
- java - 使用依赖于配置文件中的变量的不同 bean 实现
- java - 使 TestNG 测试依赖于成功完成的测试
- nginx - 阻止对除某些 ip 之外的 nginx url 的访问
- ios - Xcode IB - UILabel 多行文本换行问题 iPhone X + 较新型号
- java - 无法解析字符串符号 AndroidManifest.xml
- ibm-integration-bus - IBM Integration Toolkit (Eclipse) 无法创建新的本地集成节点
- java - 无法使用 Univocity 解析器解析日期
- java - 在请求范围内使用 AspectJ 拦截所有 JDBC 调用并作为响应返回