1

我有以下字符串列表:

M64.933,9.425
M53.333,19
M81.333,20.67
M90,33

我需要提取数字整数或小数组,我有以下正则表达式(\d*.*\d+)适用于第一组我的结果是:

["64.933", "64.933"]
["53.333", "53.333"]
["81.333", "81.333"]
["90", "90"]

分别,我怎样才能得到第二组?像这样:

["64.933", "9.425"]
["53.333", "19"]
["81.333", "20.67"]
["90", "33"]
4

1 回答 1

1

尝试使用这个正则表达式/\d+(\.\d+)?/g

var s = 'M64.933,9.425';
s.match(/\d+(\.\d+)?/g); // => ["64.933", "9.425"]

例如:

var ss = ["M64.933,9.425", "M53.333,19", "M81.333,20.67", "M90,33"]
var ns = ss.map(function(s) { return s.match(/\d+(\.\d+)?/g); });
ns // => [["64.933","9.425"],["53.333","19"],["81.333","20.67"],["90","33"]]
于 2012-05-11T15:05:18.213 回答