简体   繁体   English

Java正则表达式查找两个大写字母,后跟一个空格和七个数字

[英]Java regex to find two upper case letters, followed by one space and seven digits

I want to find a regex for the following pattern: "AA XXXXXXX" (two characters, one space and 7 digits). 我想为以下模式找到一个正则表达式: "AA XXXXXXX" (两个字符,一个空格和7位数字)。

Example: "AA 1234567" . 例如: "AA 1234567"

Now I can't find the answer. 现在我找不到答案了。

The pattern you want is: 您想要的模式是:

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

exactly two chars (upper or lower case) followed by space followed by exactly 7 digits. 正好两个字符(大写或小写),后跟空格,后跟正好7位数字。

If the characters can only be uppercase like in the sample string: 如果字符只能像示例字符串中那样是大写字母:

[A-Z]{2} [0-9]{7}

In Java: 在Java中:

Pattern p = Pattern.compile("[A-Z]{2} [0-9]{7}");
Matcher m = p.matcher("AA 1234567");
boolean b = m.matches();

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

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