no-control-regex

禁止在正则表达式中使用控制字符

配置文件 中的 "extends": "eslint:recommended" 属性启用了该规则

控制字符是 ASCII 范围 0-31 中的特殊不可见字符。这些字符很少在 JavaScript 字符串中使用,因此包含显式匹配这些字符的元素的正则表达式很可能是错误的。

规则详情

此规则不允许控制字符和某些与正则表达式中的控制字符匹配的转义序列。

正则表达式模式的以下元素被认为是可能的键入错误,因此被此规则禁止:

    VHWgpyYG9N/0xIqxNku8sw6k3GhvHwOyLOd96h6L1HABm4Jn4fchcV8W/1X0fTVJ7hi5WQTqCBdSxqy57CzjXRVo6Y6PF2KuMT3QQCD+Gwi4/yuKCC9d3xU15D5eXJoKcrWuR53R2QztgKLYfJxz51mZK6MLQH7wvMaRUj7g4/Hi7uL2Efde4KnVHATixXt3I9Ce5Fd2BUu+yRyuO5TWEqCjEIfAtwXV/5C1aMhnAOxyCS2oe3g6do4ZfClMHnWwSyNp7ugF3jYnvnaT9D5M+bmKZhIMrHwy4UU90u9S4hG2wz8ZJiH5YGAC3aNOvmryHwiW0Q1kTtROlnbGnikrCvQ2gzasGxotPbt+oBB8o8Wqw/o3LCwgaWdSuQMIqO1e8FU8BwP0Yk+jdTgWYdqlLg==

j8mvU2smXLbLZXwl7tbPzoxUQUNIWKaUaSkvU1LwBV5ITw8iHasORepP45g3WhCdbpUdfLvBOAUEpegs/nGprzaTZJZvlxYD/e75yBNogC8=

P6820Z8G9wSG50SW7a53cABVQLzOImcIRV+hQUkxjXCO67pG2wyQwHch0OYzHhMo

/*eslint no-control-regex: "error"*/

var pattern1 = /\x00/;
var pattern2 = /\x0C/;
var pattern3 = /\x1F/;
var pattern4 = /\u000C/;
var pattern5 = /\u{C}/u;
var pattern6 = new RegExp("\x0C"); // raw U+000C character in the pattern
var pattern7 = new RegExp("\\x0C"); // \x0C pattern

L9CfmI+BHDwYx59RS77HEHanEO40ClscOusGIf+RQNhowUc7Zz7f+Hb0VCfK93W9

/*eslint no-control-regex: "error"*/

var pattern1 = /\x20/;
var pattern2 = /\u0020/;
var pattern3 = /\u{20}/u;
var pattern4 = /\t/;
var pattern5 = /\n/;
var pattern6 = new RegExp("\x20");
var pattern7 = new RegExp("\\t");
var pattern8 = new RegExp("\\n");

已知限制

HaCO8NWqHL/xl5AEWpCltu5OKZ9Lyo6rA+Dq/5UlPqTDS9bOsKGhQDW9v3hHIHKzHI1A4glhpoTZObMEwVo55kUBbmUFdBZ3wbqr3PUubFILxbyVPkRBKT7PRlcV4ZdXSs6hwei5w2zxYrwSCME1PU4FDFD/UMdbo+8cymZ2wpWLIif5Q1bk0p353Ot8xdzp1rDdJiWsLrArC+9Wu6AP4qErd4txMJ8YRlQqrrt2R1HOkJzBr5Wg+oIHNExtDoWlIT/uGO3QxWotrtq05x2I00KYHOPXUZoB0WHtsnud8xo0SuWGljaSJloZC+QaPBlnZpcC2FUwLjOza9a62tuPDhidFg9keaEwE2iQY/TSYzRzp7OyAEiRm+aPsvRtyM0irb2Ag180qXI6AB4Saw+6iyTIoPz+OqLQzGCTuyGKxqapfeVRjJ1CiFkrrNybmkbU

/*eslint no-control-regex: "error"*/

new RegExp("\t"); // disallowed since the pattern is: <TAB>

new RegExp("\\t"); // allowed since the pattern is: \t

VucT9vGnrV8yuDXWIZGnEAO/3aYB/Jcc+SnjsJTweXSa+rTTXV8TYHdMeYai0OofMnqLc+L4OkjFlFWq8X6JnVzEd1/q3de9iMnAeIUOR8/mqUrWC/LbsfywVfwGh2DvGEoeV0oJKwz8VhZ4jj6Qnm0deOTRdm/QeOlcS4JAICn+Yp+KZLA05GKhWiFFGwz1TL+/aB3zNkiYKpYoW67Cr2iNXOzCogWqsXii+tBCEKzOuA2kDd4fxsybKUo6C89RKiRWIB57TPa9PkZ3+HBIv9aJoBCGscOvLloIFbRoWq+4hkcLEQEp+OdGnEKStZ6Y

何时不使用

yffw9QAfpWY5O9h4DEmCfCM2rFMDYmHubVSdranchvB+r3XCc0iPCs7mZo1o3pAEYyqPKJtN4CFPzNTBQMkgTHZ+q93ILPlQQ9nWK2ETNh5Uk7VTJvQZnctMKjQi7mlK