简体   繁体   English

python正则表达式匹配模式

[英]python regular expression match a pattern

So, I have been trying to match a simple pattern like B0000001 where just the first character be an alphabet " B " and rest should be numbers. 因此,我一直在尝试匹配一个简单的模式,例如B0000001 ,其中第一个字符是字母“ B ”,其余字符应该是数字。 The total length should be 9. 总长度应为9。

I tried the pattern "^B[0-9]{7}$" but it fails most of the time. 我尝试了模式"^B[0-9]{7}$"但大多数情况下它失败。 Any suggestions? 有什么建议么?

Use this expresion: 使用此表达式:

^B\d{8}$

Demo 演示版

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

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