【前端】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"]

 

posted @ 2016-02-20 15:25  赵康  阅读(468)  评论(0编辑  收藏  举报