Javascript 删除大括号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8307039/
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
Javascript Remove Braces
提问by Sinal
I have the string "{Street Name}, {City}, {Country}" and want to remove all braces. The result should be "Street Name, City, County". How do I do that?
我有字符串 "{Street Name}, {City}, {Country}" 并想删除所有大括号。结果应为“街道名称、城市、县”。我怎么做?
回答by Trott
If you want to remove all occurrences of {
and }
whether or not they are matched pairs, you can do it like this:
如果要删除所有出现的项{
以及}
它们是否匹配,可以这样做:
var str = "{Street Name}, {City}, {Country}";
str = str.replace(/[{}]/g, "");
回答by meouw
The character class [{}]
will find all curly braces
字符类[{}]
会找到所有的花括号
var address = "{Street Name}, {City}, {Country}";
address = address.replace( /[{}]/g, '' );
console.log( address ) // Street Name, City, Country
回答by adrianton3
str = str.replace(/[{}]/g,"");
回答by Gourav khanna
Use this javascript simple code in your respective function to remove braces :
在您各自的函数中使用此 javascript 简单代码删除大括号:
var str = '{Street Name}, {City}, {Country}';
str = str.replace(/{/g, '').replace(/}/g, '');