正则相关[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"] 结果已数组形式输出

 

相关文章:

  • 2021-11-28
  • 2022-01-28
  • 2021-10-09
  • 2021-06-04
  • 2022-01-08
  • 2021-09-16
  • 2022-01-17
  • 2021-04-09
猜你喜欢
  • 2021-10-19
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
相关资源
相似解决方案