Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用正则表达式删除带有数字和特殊字符的字符串_Javascript_Regex - Fatal编程技术网

Javascript 如何使用正则表达式删除带有数字和特殊字符的字符串

Javascript 如何使用正则表达式删除带有数字和特殊字符的字符串,javascript,regex,Javascript,Regex,使用正则表达式删除带有数字和特殊字符的字符串 var string = "[Account0].&[1]+[Account1].&[2]+[Account2].&[3]+[Account3].&[4]"; var numbers = string.match(/(\d+)/gi); alert(numbers.join(',')); 这里的输出是:0,1,1,2,2,3,3,4 但是我想要下面的输出1,2,3,4 谁能帮帮我吗 谢谢,看你想要

使用正则表达式删除带有数字和特殊字符的字符串

  var string = "[Account0].&[1]+[Account1].&[2]+[Account2].&[3]+[Account3].&[4]";
    var numbers = string.match(/(\d+)/gi);
    alert(numbers.join(','));
这里的输出是:0,1,1,2,2,3,3,4

但是我想要下面的输出1,2,3,4

谁能帮帮我吗


谢谢,

看你想要的是[\d+],像这样使用exec

var myRe = /\[(\d+)\]/gi;

var myArray, numbers = [];

while ((myArray = myRe.exec(string)) !== null) {
    numbers.push(myArray[1]);
}

看你想要的是[\d+],像这样使用exec

var myRe = /\[(\d+)\]/gi;

var myArray, numbers = [];

while ((myArray = myRe.exec(string)) !== null) {
    numbers.push(myArray[1]);
}

看你想要的是[\d+],像这样使用exec

var myRe = /\[(\d+)\]/gi;

var myArray, numbers = [];

while ((myArray = myRe.exec(string)) !== null) {
    numbers.push(myArray[1]);
}

看你想要的是[\d+],像这样使用exec

var myRe = /\[(\d+)\]/gi;

var myArray, numbers = [];

while ((myArray = myRe.exec(string)) !== null) {
    numbers.push(myArray[1]);
}

我想在这种情况下最简单的解决方案是:

\[(\d+)\]
简单地说,您只需要用括号括起来的数字


关于

我想在这种情况下最简单的解决方案是:

\[(\d+)\]
简单地说,您只需要用括号括起来的数字


关于

我想在这种情况下最简单的解决方案是:

\[(\d+)\]
简单地说,您只需要用括号括起来的数字


关于

我想在这种情况下最简单的解决方案是:

\[(\d+)\]
简单地说,您只需要用括号括起来的数字

关于

您可以做:

string = "[Account0].&[1]+[Account1].&[2]+[Account2].&[3]+[Account3].&[4]";
repl = string.replace(/.*?\[(\d+)\][^\[]*/g, function($0, $1) { return $1 });
//=> "1234"
你可以做:

string = "[Account0].&[1]+[Account1].&[2]+[Account2].&[3]+[Account3].&[4]";
repl = string.replace(/.*?\[(\d+)\][^\[]*/g, function($0, $1) { return $1 });
//=> "1234"
你可以做:

string = "[Account0].&[1]+[Account1].&[2]+[Account2].&[3]+[Account3].&[4]";
repl = string.replace(/.*?\[(\d+)\][^\[]*/g, function($0, $1) { return $1 });
//=> "1234"
你可以做:

string = "[Account0].&[1]+[Account1].&[2]+[Account2].&[3]+[Account3].&[4]";
repl = string.replace(/.*?\[(\d+)\][^\[]*/g, function($0, $1) { return $1 });
//=> "1234"