简体   繁体   English

使用javascript删除特殊字符的正则表达式

[英]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.

相关问题 使用xregexp的javascript正则表达式替换特殊字符,但允许白名单 - javascript regular expression to replace special characters, but allow a whitelist, using xregexp 不允许特殊字符的 Javascript 正则表达式 - Javascript Regular Expression that diallows special characters javascript-正则表达式字母数字和特殊字符 - javascript- regular expression alphanumeric and special characters 用于识别所有特殊字符的javascript正则表达式 - javascript regular expression to recognize all special characters 在Javascript中使用正则表达式匹配特殊字符“-” - Matching Special character '-' using Regular expression in Javascript 如何使用jQuery正则表达式验证字符,数字和特殊字符? - How to validate characters, numbers and special characters using jQuery regular expression? 如何在Wordpress,PHP,JavaScript上使用正则表达式从字符串(URL)中删除特殊字符 - How to remove special characters from a string (URL) using regular expression on wordpress, php, javascript javascript正则表达式,至少3个字并允许特殊字符 - javascript regular expression of minimum 3 words and allow special characters JavaScript正则表达式替换字符串中的转义特殊字符 - JavaScript Regular Expression to Replace Escape Special Characters from String JavaScript正则表达式-仅接受两个不带特殊字符的单词 - JavaScript Regular Expression - Accept only two words with no special characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM