any86 / any-rule

🦕 常用正则大全, 支持web / vscode / idea / Alfred Workflow多平台
https://any-rule.vercel.app/
MIT License
8.53k stars 830 forks source link

「优化」座机正则表达式存在冗余 #319

Open condorheroblog opened 3 months ago

condorheroblog commented 3 months ago

原始正则:

/^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/

image

正则中的第二个定位符(^)是不必要的,可以删除,保留一个即可:

image

/^(?:(?:\d{3}-)?\d{8}|(?:\d{4}-)?\d{7,8})(?:-\d+)?$/

通过 regexp/no-useless-assertions 检查发现