问题描述
我想要以下格式的 VB.NET 正则表达式
I want VB.NET regular expression for below format
7966-591739
我的意思是用户必须先输入 4 数字 字符,然后是 "-" 和 6 数字后面的字符对于数字和字符都是可选的.在我的情况下,用户也可以输入
I mean user must have to enter 4 numeric characters first then "-" and then 6 numeric characters after that optional for numeric as well as for characters. In my case user can also enter
7966-591739 分机 562
7966-591739 ext 562
7966-591739 x 434
7966-591739 x 434
请推荐!
推荐答案
我相信英国号码通常在-"字符前有 5 位数字.
I belive that UK number often have 5 digits before your '-' character.
我已更新@NawaMan 的答案以使其运行并删除捕获组:
I've updated @NawaMan's answer to make it run and to remove the capturing groups:
^[0-9]{4,6}\-[0-9]{6}(?:\s(?:ext|x)\s[0-9]{3,4})?$
在这里捕获数字组:
^([0-9]{4,6})\-([0-9]{6})(?:\s(?:ext|x)\s([0-9]{3,4}))?$
这里是清理过的表达式:
And here is the expression cleaned up:
^(\d{4,6})\-(\d{6})(?:\s(?:ext|x)\s(\d{3,4}))?$
更新 - 根据 OP 的要求.
UPDATED - To as per OP's request.
这篇关于英国电话号码的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!