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

相关文章:

  • 2022-01-25
  • 2021-07-04
  • 2022-12-23
  • 2022-03-07
  • 2021-07-02
  • 2021-08-26
  • 2022-02-06
  • 2021-10-08
猜你喜欢
  • 2022-03-02
  • 2022-03-02
  • 2022-12-23
  • 2021-08-18
  • 2022-02-26
  • 2021-06-26
相关资源
相似解决方案