简体   繁体   English

验证匹配不能为空

[英]Validate that match can't be empty

Is it possible that javascript linter will tell if regex will allways produce nonempty match? javascript linter是否可以判断正则表达式是否始终会产生非空匹配?

s.match(/\w*/)[0]           // valid
s.match(/\w+/)[0]           // invalid
s.match(/id(\d{7})/)[1]     // invalid
s.match(/id(\d{7})|$/)[1]   // valid

PS: Same question in Russian. PS: 同样的俄语问题。

No, eslint cannot analyze code like this at least out of the box. 不,eslint至少无法立即分析此类代码。

Code linting is a type of static analysis that is frequently used to find problematic patterns or code that doesn't adhere to certain style guidelines. 代码棉绒是一种静态分析,通常用于查找有问题的模式或不符合某些样式准则的代码。

https://eslint.org/docs/about/ https://eslint.org/docs/about/

Maybe you could write a plugin to validate those cases. 也许您可以编写一个插件来验证这些情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM