[英]How to remove a character from a string
I need to delete a # in a url for example I have the string: 我需要在网址中删除#,例如我有字符串:
message: hello http://www.google.it#readme
and I must delete '#' character. 我必须删除'#'字符。 This is my code in node.js:
这是我在node.js中的代码:
messagge.replace(new RegExp(/((http|https)\S*#\S*)+/g),function(x){
x.replace('#','');
console.log(x);
});
The console prints the link but the link is not change is: http://www.google.it#readme . 控制台打印链接但链接未更改为: http://www.google.it#readme 。 Anyone can help to find a solution?
任何人都可以帮助找到解决方案?
Assign the replacement to x: 将替换分配给x:
messagge.replace(new RegExp(/((http|https)\S*#\S*)+/g),function(x){
x = x.replace(new RegExp(/#/g),'');
console.log(x);
});
Use it like this to eliminate all the '#' in your link. 像这样使用它来消除链接中的所有“#”。
x = x.replace(/\#/g,'');
or like this to eliminate just one: 或者像这样只消除一个:
x = x.replace('#','');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.