Lil*_*its 3 regex ms-access vba
我是正则表达式的新手,我正在尝试使用正则表达式验证数据库中的收据编号.
我们的收据可以采用以下格式:
我尝试过使用一堆不同的正则表达式组合,但似乎都没有.现在我有:
(\d)(\d)(\d)(\d)(\d)(\d)(\d)([a-z])?([a-z])?([a-z])?
但这允许超过七位数,并允许超过3个字母.
这是我在Access 2010中的VBA函数,它将验证表达式:
Function ValidateReceiptNumber(ByVal sReceipt As String) As Boolean
    If (Len(sReceipt) = 0) Then
        ValidateReceiptNumber = False
        Exit Function
    End If
    Dim oRegularExpression     As RegExp
'   Sets the regular expression object
    Set oRegularExpression = New RegExp
    With oRegularExpression
'   Sets the regular expression pattern
        .Pattern = "(\d)(\d)(\d)(\d)(\d)(\d)(\d)([a-z])?([a-z])?([a-z])?"
'   Ignores case
        .IgnoreCase = True
'       Test Receipt string
        ValidateReceiptNumber = .Test(sReceipt)
    End With
End Function
Roh*_*ain 10
您可能需要在末端使用锚点.您的正则表达式可以简化为: -
^\d{7}[a-z]{0,3}$
\d{7}完全匹配7 digits.你不需要使用\d7次.{0,3} 创建一个范围,并匹配前面模式的0到3次重复,Caret(^) 匹配行的开头Dollar($) 匹配行的结尾.| 归档时间: | 
 | 
| 查看次数: | 8281 次 | 
| 最近记录: |