js 面试题正则相关
正则相关[i不区分大小写,g匹配全部数据]
var str = "Hello word! I think word is good.";
1、替换str中的word为javascript
str.replace(/word/ig,'javascript'); //Hello javascript! I think javascript is good. 结果为替换后的字符串
2、判断str中是否包含word
/word/ig.test(str); //true 布尔值
3、获取str中所有word
str.match(/word/ig); //array ["word", "word"] 结果已数组形式输出