VB.net中的正则表达式 [英] regular expression in VB.net
问题描述
我希望检查这种格式类似于这个MH-9940
如何自定义正则表达式以检查前2-3个字母是否是来自az的大写然后应该有连字符后跟4个数字0-9
链接到关于正则表达式的好解释也会有所帮助
这里是通过当前代码,但它缺乏我想要的东西
i wish to check for this format similar to this MH-9940
how do i customize regular expression to check if first 2-3 letters are capital from a-z then there should be hyphen followed by four digits from 0-9
link to good explanation about regular expression will also be helpful
here is by current code but its lacking what i want
If Not Regex.IsMatch(TextBox2.Text, "^[MH-]") Then
MsgBox("Enter proper format!!!" & vbCrLf & "Invalid Bus Number ")
Exit Sub
推荐答案
试试这个: ^ [AZ] {2,3} -\d {4}
Try this: ^[A-Z]{2,3}-\d{4}
为了测试学习目的,我建议你下载 Regex Coach [ ^ ]。
查看此模式:
See this pattern:
^*([A-Z]{2,3}\-[0-9]{4}).*
经测试在 Rad Software Regex Designer [ ^ ]和这组记录:
Tested on Rad Software Regex Designer[^] and this set of records:
MH-9940
NH-1940
AGV-9Az0
FG-5940
MZ-92X0
AHV-9930
IgnorePatternWhiteSpace
和 Mulitline
设置为 TRUE
。
返回:
with IgnorePatternWhiteSpace
and Mulitline
set to TRUE
.
Returns:
MH-9940
NH-1940
FG-5940
AHV-9930
这就是你要找的东西吗?
你会在这里找到许多有用的信息: http://www.regular-expressions.info/reference.html [ ^ ]
这篇关于VB.net中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!