首页 > 解决方案 > 从问号中剪切网址

问题描述

我从 IPB 论坛阅读了新主题,当我想要获取主题链接时,我得到了这个结果:

http://1234.23123/forum/topic/2-rgewgreg/?do=findComment&comment=2

如何从网址中删除这个?do=findComment&comment=2 ?它是动态的,所以如果它识别出问号然后删除其余的 url 和问号会很好。

标签: node.jsregex

解决方案


你不需要使用正则表达式,你可以使用

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/


推荐阅读