no-regex-spaces
Disallow multiple spaces in regular expressions
        ✅ Recommended
        
            The "extends": "eslint:recommended" property in a configuration file enables this rule
        
        🔧 Fixable
        
            Some problems reported by this rule are automatically fixable by the --fix command line option
        
正则表达式可能非常复杂且难以理解,这就是为什么为了避免错误而尽可能保持其简单的原因。在正则表达式中,一个比较容易出错的地方是使用一个以上的空格,如:
var re = /foo   bar/;
在这个正则表达式中,很难说出有多少个空格要被匹配。最好是只使用一个空格,然后指定预计有多少个空格,例如:
var re = /foo {3}bar/;
现在非常清楚的是,有三个空间预计将被匹配。
规则细节
这条规则不允许在正则表达式字面上有多个空格。
使用此规则的错误示例:
                            
                                Open in Playground
                            
/*eslint no-regex-spaces: "error"*/
var re = /foo   bar/;
var re = new RegExp("foo   bar");
使用此规则的正确示例:
                            
                                Open in Playground
                            
/*eslint no-regex-spaces: "error"*/
var re = /foo {3}bar/;
var re = new RegExp("foo {3}bar");
何时不用
如果你想在正则表达式中允许多个空格,那么你可以安全地关闭这个规则。
Related Rules
Version
This rule was introduced in ESLint v0.4.0.