var testString = "Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.";
var expression = /and/gi;
var andCount = testString.match(expression).length;
/
是这个正则表达式的头部
the
是我们想要匹配的模式
/
是这个正则表达式的尾部
g
代表着 global
(全局),意味着返回所有的匹配而不仅仅是第一个。
i
代表着忽略大小写,意思是当我们寻找匹配的字符串的时候忽略掉字母的大小写。
原文:https://www.cnblogs.com/chendi618/p/11000447.html