正则表达式 RegExp 与 JavaScript API s.match(reg)
// 字符
var s = "The quick fox jumps over a lazy dog.";
var reg = new RegExp("o", "g");// 或 var reg = /o/g;
var arr = s.match(reg);
console.log(arr.length);// 3
// 字符串
var s = "The quick fox jumps over a lazy dog.";
var reg = new RegExp("fox", "g");
var arr = s.match(reg);
console.log(arr.length);// 1