[英]Regex to allow a space instead of following numbers after first two letters
我需要一个允许AB123
有一个空格的正则表达式,即不允许使用AB123
但应该允许使用AB 123
?
This pattern will do the work: ^[a-zA-Z]{2} \\d+$
这种模式将完成工作:
^[a-zA-Z]{2} \\d+$
Explanation:解释:
^
- match beginning of a string ^
- 匹配字符串的开头
[a-zA-Z]{2}
- match two letters (upper- or lowercase), [a-zA-Z]{2}
- 匹配两个字母(大写或小写),
- match space
- 匹配空间
\\d+
- match one or more digits \\d+
- 匹配一位或多位数字
$
- match end of a string $
- 匹配字符串的结尾
Here is the regex [a-zA-Z]{2}\\s\\S*
这是正则表达式
[a-zA-Z]{2}\\s\\S*
[a-zA-Z]
means character from a to Z [a-zA-Z]
表示从 a 到 Z 的字符
{2}
means character twice {2}
表示字符两次
\\s
means white space \\s
表示空白
\\S
means non white space. \\S
表示非空白。
*
duplicate with 0 or more *
重复 0 个或多个
https://regex101.com/r/uWYci4/1 https://regex101.com/r/uWYci4/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.