Can Javascript RegExp do partial case insensitivity?

后端 未结 5 617
我寻月下人不归
我寻月下人不归 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:58

    Don't think so. I'd suggest doing this:

    var m;
    var str = "teXT To seArcH TOP SECRET";
    if ((m = str.match(/text to search (top secret)/i)) && m[1].match(/TOP SECRET/)) {
      // matched.
    }
    

提交回复
热议问题