AS3:使用replace获取在Regex模式中的括号中找到的结果

时间:2011-04-09 13:18:45

标签: regex flash actionscript-3 string replace

这是我目前的解决方法:

var str = "testing123";
var pattern = /([a-z]*)([0-9]*)/g;
var args;
str.replace(pattern, function(){args = arguments; return arguments[0];});
trace(args);

输出:

testing123,testing,123

但它想这样做:

var str = "testing123";
var pattern = /([a-z]*)([0-9]*)/g;
str.match(pattern);
trace(arguments);

这可能吗?

1 个答案:

答案 0 :(得分:2)

var str = "testing123";
var pattern = /([a-z]*)([0-9]*)/g;
var hits:Object = pattern.exec (str);
for( var i:String in hits ) {
trace( i + " "+ hits[i] );
}

//outputs
0 testing123
1 testing
2 123
input testing123
index 0