Almost nine years ago, Cloudflare was a tiny company and I was a customer not an employee. Cloudflare had launched a month earlier and one day alerting told me that my little site, jgc.org, didn’t seem to have working DNS any more. Cloudflare had pushed out a change to its use of Protocol Buffers and it had broken DNS.
多选结构是回溯的主要原因之一。例如使用u|v|w|x|y|z和[uvwxyz]去匹配字符串“The name “McDonald’s” is said “makudonarudo” in Japanese”。最终[uvwxyz]只需要34次尝试就能够成功,而如果使用u|v|w|x|y|z则需要在每个位置进行6次回溯,在得到同样结果前总共有198次回溯
var reg1=/.*!/;
// 更优表达式
var reg2=/[^!]*!/;
var str = 'The CPU exhaustion was caused by a single WAF rule that contained a poorly written regular expression that ended up creating excessive backtracking';
var result1=reg1.exec(str);
var result2=reg2.exec(str);
console.log(result1, result2);