7位不以0或1开头的正则表达式 [英] Regular expression for 7 digits not starting with 0 or 1

查看:40
本文介绍了7位不以0或1开头的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图只接受不以 0 或 1 开头的 7 位数字

I am trying to accept only 7 digit long number not starting with 0 or 1

7089097 - 好的

7089097 - OK

0089097 - 不好

0089097 - Not good

1089097 - 不好

1089097 - Not good

这是我试过的:

^\[2-9][0-9]{7}$ 

而且不工作:)

推荐答案

这个正则表达式会起作用:

This regex will work:

^[2-9][0-9]{6}$ 

7 位数字中的 1 被第一个位置 2-9 消耗,然后接下来的 6 位数字可以从 0-9

Out of 7 digits 1 is consumed by first position 2-9 and then next 6 digits can be from 0-9

这篇关于7位不以0或1开头的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆