[英]RegEx Help (13 length digit, ends in specific digits)
Another RegEx question for a search I'm trying to do. 我正在尝试搜索的另一个RegEx问题。
The Problem : Determine if user input is 13 digits long (numbers only) and ends with 52,56, or 57. 问题 :确定用户输入是否为13位数长(仅数字),并以52,56或57结尾。
My current not working solution : [0-9]52|56|57${13}
. 我当前无法正常工作的解决方案 :
[0-9]52|56|57${13}
。 I also tried [0-9]52|56|57{13}$
but no dice. 我也尝试了
[0-9]52|56|57{13}$
但没有骰子。
Help is appreciated. 感谢帮助。
Try this regular expression: 试试这个正则表达式:
^[0-9]{11}(52|56|57)$
This is what it means: 这是什么意思:
^ Start of string [0-9] Any character in 0-9 {11} The previous token must match exactly 11 times. (52|56|57) Alternation - any one of the possibilities must match $ End of string
You could also in this case simplify it to: 在这种情况下,您还可以将其简化为:
^[0-9]{11}5[267]$
You have 13 digits 11 of which can be any digit and the next two must be 52,56, or 57. 11 digits in regex notation is something like \\d{11}
. 您有13位数字,其中11位可以是任何数字,接下来的两位数必须是52,56或57。正则表达式中的11位数字类似于
\\d{11}
。 The 'or' operator is denoted by the symbole |
“或”运算符由符号
|
表示|
so 52 or 56 or 57
becomes 52|56|57
. 因此
52 or 56 or 57
变为52|56|57
。 The resulting regex looks like \\d{11}(52|56|57)
. 生成的正则表达式看起来像
\\d{11}(52|56|57)
。 Parentheses are used to disambiguate. 括号用于消除歧义。
Remember that you can construct complex regular expressions from simpler ones. 请记住,您可以从简单的正则表达式构造复杂的正则表达式。 This approach works always ;)
这种方法始终有效;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.