我从IPB论坛上阅读了新主题,当我想要获取主题链接时,我得到了以下结果:
http://1234.23123/forum/topic/2-rgewgreg/?do=findComment&comment=2
如何从网址中删除此?do = findComment&comment = 2 ? 它是动态的,因此,如果识别出问号,然后删除其余的url和问号,那就太好了。
答案 0 :(得分:1)
您不需要使用正则表达式即可使用
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/
答案 1 :(得分:0)
请您尝试以下。
var a = 'http://1234.23123/forum/topic/2-rgewgreg/?do=findComment&comment=2';
console.log(a.replace(/\?.*/g,''));
答案 2 :(得分:-1)
您可以使用Substring函数 像这样
string.substring(starposition,length);
示例 如果是php
var str="http://1234.23123/forum/topic/2-rgewgreg/?do=findComment&comment=2";
var res= str.substring(0,str.indexof("?")-1);
console.log(res);