Can Javascript RegExp do partial case insensitivity?

后端 未结 5 622
我寻月下人不归
我寻月下人不归 2021-01-14 14:35

I want to know if Javascript RegExp has the ability to turn on and off case insensitivity within the regular expression itself. I know you can set the modifier for the entir

5条回答
  •  清歌不尽
    2021-01-14 14:45

    What you can do is build your regex like this :

    var str = "teXT To seArch";
    var r = new RegExp(
      str.split('').map(function(c){return '['+c.toLowerCase()+c.toUpperCase()+']'}).join('')
      + ' TOP SECRET'
    );
    

提交回复
热议问题