Javascript 如何从字符串中删除字符
我需要删除url中的#,例如,我有以下字符串:Javascript 如何从字符串中删除字符,javascript,node.js,Javascript,Node.js,我需要删除url中的#,例如,我有以下字符串: message: hello http://www.google.it#readme 我必须删除“#”字符。这是我在node.js中的代码: messagge.replace(new RegExp(/((http|https)\S*#\S*)+/g),function(x){ x.replace('#',''); console.log(x);
message: hello http://www.google.it#readme
我必须删除“#”字符。这是我在node.js中的代码:
messagge.replace(new RegExp(/((http|https)\S*#\S*)+/g),function(x){
x.replace('#','');
console.log(x);
});
控制台打印链接,但链接未更改为:。任何人都可以帮助找到解决方案?将替换项分配给x:
messagge.replace(new RegExp(/((http|https)\S*#\S*)+/g),function(x){
x = x.replace(new RegExp(/#/g),'');
console.log(x);
});
这样使用它可以删除链接中的所有“#”
x = x.replace(/\#/g,'');
或者像这样只删除一个:
x = x.replace('#','');