我如何能得到2字母表7数字1字母格式的字符串,正则表达式在.NET [英] how can I get 2 alphabet 7 numeric 1 alphabet format for a string in regex in .net

查看:208
本文介绍了我如何能得到2字母表7数字1字母格式的字符串,正则表达式在.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,对于格式为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.

这篇关于我如何能得到2字母表7数字1字母格式的字符串,正则表达式在.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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