JavaScript exec()方法

时间:2018-12-26 10:07:36   收藏:0   阅读:138

exec() 方法用于检索字符串中的正则表达式的匹配。返回一个数组,其中存放匹配的结果。如果未找到匹配,则返回值为 null。

var str = "我今年25岁明年26岁后年27岁千年24岁";

var reg=/\d+/g;

var result;
while(result=reg.exec(str)){
console.log(result[0])
}

 

//检索出字符串中的所有数字

25
26
27
24

原文:https://www.cnblogs.com/h5it/p/10177460.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!