javascript - 验证匹配不能为空

标签 javascript regex eslint static-analysis null-check

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.

最佳答案

不,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/

也许您可以编写一个插件来验证这些情况。

关于javascript - 验证匹配不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50687816/

相关文章:

Python 正则表达式困惑

python在多行中匹配感叹号

javascript - 2 个验证器只有 1 个抛出可捕获的 isvalid 错误

javascript - Eslint 不检查 .ts 或 .tsx 文件

typescript - Vue/TypeScript/ESLint/Prettier/Vetur 格式不起作用

javascript - 检查输入文本是否已填充并显示不同的div

javascript - 关于多个ready()的问题

Javascript 改进了原生 for 循环

javascript - 如何使用 nodejs express 应用程序配置 eslint

javascript - 错误 错误 : Uncaught (in promise): invalid link: SosPopPage