[英]Regular expression using javascript for removing the special characters
How to write the regular expression for the below string using Javascript. 如何使用Javascript为以下字符串编写正则表达式。
[Account].&[1]+[Account].&[2]+[Account].&[3]+[Account].&[4]
T need the following output format T需要以下输出格式
1,2,3,4
emoving all the strings and special characters. 去掉所有的字符串和特殊字符。
/\[(\d+)\]/g
That will return you the array containing all numbers in the string, which you then can join using ,
as delimiter. 这将返回包含字符串中的所有数字,然后你可以加入使用数组,
作为分隔符。
var string = "[Account].&[1]+[Account].&[2]+[Account].&[3]+[Account].&[4]";
var numbers = string.match(/\[(\d+)\]/gi);
alert(numbers.join(','));
尝试这个
yourString.replace('[^a-zA-Z0-9 -]', '');
This will give you an array of the extracted numbers: 这将为您提供提取数字的数组:
var ar1 ='[Account5].&[1]+[Account6].&[2]+[Account7].&[3]'.match(/\[\d+\]/g);
And to assert you extract only numbers between brackets: 并断言您仅提取括号之间的数字:
var ar2 = ar1.map(function (elt) { return elt.replace(/\[(\d+)\]/, "$1"); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.