从正则表达式中提取数字

时间:2016-08-17 02:05:28

标签: javascript

var myString = 'Sent from your Zoom trial account - Your verification code is: 621226';
var regEx = /(\d+)$/g;
var result = regEx.exec(myString);

然而结果= [621226,621226]而不仅仅是[621226]

http://plnkr.co/edit/8ZbFHDAk0iLwEjpfkQaq?p=info

1 个答案:

答案 0 :(得分:0)

.match()regEx一起用作myString链接的参数。

var myString = 'Sent from your Zoom trial account - Your verification code is: 621226';
var regEx = /(\d+)$/g;
var result = myString.match(regEx);
console.log(result);

plnkr http://plnkr.co/edit/cdwFsPKq9X3tCnub6FzL?p=preview