【前端】String.prototype.match() 用法详解

1 var str="1 plus 2 equal 3"
2 
3 // 正则表达式
4 console.log(str.match(/\d+/g)); // ["1", "2", "3"]
5 console.log(str.match(/\d+/)); // ["1", index: 0, input: "1 plus 2 equal 3"]
6 
7 // 字符串
8 console.log(str.match(' ')); // [" ", index: 1, input: "1 plus 2 equal 3"]

原文地址:https://www.cnblogs.com/forzhaokang/p/5203363.html