JSLint “insecure ^” in regular expression

后端 未结 3 1309
后悔当初
后悔当初 2020-11-29 09:55

JSLint reports Insecure \'^\' for the following line. Why is that? Or is it just going to complain any time I want to negate a character class?

// r         


        
3条回答
  •  萌比男神i
    2020-11-29 10:41

    Consider using \W instead of /^\w/

    "!$7s-gd,&j5d-a#".replace(/\W/g, '');
    

    For your particular case this would not work because you want to leave comma and dash characters, but I think it is worth mentioning.

提交回复
热议问题