我如何能得到2字母表7数字1字母格式的字符串,正则表达式在.NET字母表、字符串、字母、格式

由网友(宸)分享简介:例如,对于格式为aa1231231c example for the format is aa1231231c推荐答案嗯,看起来像:[a-zA-Z]{2}[0-9]{7}[a-zA-Z]给我。当然,这取决于你所说的字母和数字的意思是 - 上面只涉及ASCII字母和数字,没有口音,没有其他类型的数字等你to m...

例如,对于格式为aa1231231c

example for the format is aa1231231c

推荐答案

嗯,看起来像:

[a-zA-Z]{2}[0-9]{7}[a-zA-Z]

给我。当然,这取决于你所说的字母和数字的意思是 - 上面只涉及ASCII字母和数字,没有口音,没有其他类型的数字等你

to me. Of course it depends on what you mean by "alphabet" and "numeric" - the above only deals with ASCII letters and digits, with no accents, no other types of digits etc. You

请注意,有替代办法,如使用 D 为任意数字和 p {L〕匹配任意字母;如果你真的只的希望的ASCII字母和数字,虽然,我会用上面以明确什么是允许的。

Note that there are alternative approaches such as using d for "any digit" and p{L} to match "any letter"; if you really only want the ASCII letters and digits though, I'd use the above to make it obvious exactly what's allowed.

您可以匹配在code整个字符串,或使用 ^ $ 来在EX pression迫使它:

You can either match that as the whole string in code, or use ^ and $ to force it in the expression:

^[a-zA-Z]{2}[0-9]{7}[a-zA-Z]$

将prevent你的模式被发现在其他的文字中间。

That will prevent your pattern being found in the middle of other text.

阅读全文

相关推荐

最新文章