简体   繁体   English

证件号码正则表达式

[英]Document number regular expression

I'm trying to find a regular expression for bolivian document numbers: 我正在尝试找到玻利维亚文件编号的正则表达式:

1234567 LP or 1234567LP 1234567 LP或1234567LP

I tried using \\w?\\s?, but it accepts special characters, like * or %. 我尝试使用\\ w?\\ s ?,但是它接受特殊字符,例如*或%。 There isn't a defined number of digits (6 to 8 digits) or letters (2 to 3 letters). 没有定义的数字位数(6到8位数字)或字母(2到3个字母)。 It can has one or none white space character. 它可以有一个或没有空格字符。

Any suggestion? 有什么建议吗? Regards. 问候。

try this: 尝试这个:

\b[0-9]{6,8} ?[A-Z]{2,3}\b

(if you want to check a whole string, you must add anchors ( ^ and $ ) at the begining and at the end of the pattern. Then word boundaries are no more useful). (如果要检查整个字符串,则必须在模式的开头和结尾添加锚点( ^$ 。然后,单词边界不再有用)。 Example: 例:

^[0-9]{6,8} ?[A-Z]{2,3}$
Regex.IsMatch(input, @"^\d{6,8} ?[A-Za-z]{2,3}$");

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

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