如何从 JAVASCRIPT 中的字符串中删除括号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19583580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I remove the parenthesis from a string in JAVASCRIPT?
提问by user2447830
How can I remove the parenthesis from this string in Javascript "(23,45)" ? I want it to be like this => "23,45" please!
如何从 Javascript "(23,45)" 中的这个字符串中删除括号?我希望它是这样的 => 请“23,45”!
回答by Denys Séguret
Simply use replacewith a regular expression:
str = str.replace(/[()]/g,'')
If you just wanted to remove the first and last characters, you could also have done
如果您只想删除第一个和最后一个字符,您也可以这样做
str = str.slice(1,-1);
回答by pythonian29033
str = str.split("(").split(")").join();
回答by Satpal
回答by Barmar
If they're always the first and last characters:
如果它们总是第一个和最后一个字符:
str = str.substr(1, str.length-2);
回答by phongvan_fls
Try
尝试
"(23,45)".replace("(","").replace(")","")
回答by Noman ali abbasi
Use this regex
使用这个正则表达式
var s = "(23,45)";
alert(s.replace(/[^0-9,]+/g,''))