首页 > 解决方案 > 正则表达式 - 6 位或 9 位不小于或之间或更多的表达式

问题描述

我必须编写一个检测 6 位或 9 位的正则表达式 - 意思是:

ID 123 - it should not meet the regext as it is 3 digits
ID 1234 - it should not meet the regext as it is 4 digits
ID 12345 - it should not meet the regext as it is 5 digits
ID 123456 - it should meet the regex it is 6 digits <==========
ID 1234567 - it should not meet the regext as it is 7 digits
ID 12345678 - it should not meet the regext as it is 8 digits
ID 123456789 - it should meet the regext as it is 9 digits <==========
ID 1234567890 - it should not meet the regext as it is 10 digits
ID 12345678901 - it should not meet the regext as it is 11 digits

等等……你明白了吗?

谁能帮我解决这个问题的正则表达式?

标签: regex

解决方案


您可以尝试使用这种模式:

\b(\d{6}|\d{9})\b

推荐阅读