Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从字符串中删除字符_Javascript_Node.js - Fatal编程技术网

Javascript 如何从字符串中删除字符

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);

我需要删除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);

            });

控制台打印链接,但链接未更改为:。任何人都可以帮助找到解决方案?

将替换项分配给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('#','');