js 查找字符串中指定字符 模糊查询 不区分大小写

  var str = "hello  world ! hello  coder!" ;
  //查找‘HELLO’是否存在,找不到返回null
  var reg = new RegExp('HELLO','i') ;
  var isHas = str.match(reg);
  console.log(isHas); 
  //打印结果: ["hello", index: 0, input: "hello  world ! hello  coder!", groups: undefined]
var str="Hello world!";
//查找"Hello"
var patt=new RegExp('HELLO','i') ;
var result=patt.test(str);
console.log(result) // true

如上两种,用正则new RegExp,test/match查找可以实现,不区分大小写

posted @   黑白棋学弟  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示