我非常喜欢MS Access作为小范围数据驱动应用程序的RAD-Tool。但是,作为.Net-Developer,我真正想念的一件事是正则表达式。在验证用户输入时,它们真的很方便。我真的不知道为什么微软没有把它们放在标准的VBA-Library中。
有没有办法在MS Access VBA中使用正则表达式?
答案 0 :(得分:23)
您可以通过添加对Microsoft VBScript正则表达式库的引用来使用VBScript Regex Object。
使用示例:
Dim szLine As String
Dim regex As New RegExp
Dim colregmatch As MatchCollection
With regex
.MultiLine = False
.Global = True
.IgnoreCase = False
End With
szLine = "Analyzed range (from-to) 10 100"
regex.Pattern = "^Analyzed range"
If regex.Test(szLine) Then
regex.Pattern = ".*?([0-9]+).*?([0-9]+)"
Set colregmatch = regex.Execute(szLine)
'From
Debug.Print colregmatch.Item(0).submatches.Item(0)
'To
Debug.Print colregmatch.Item(0).submatches.Item(1)
End If
来源:http://mark.biek.org/blog/2009/01/regular-expressions-in-vba/
答案 1 :(得分:2)
您可以使用CreateObject(“vbscript.regexp”)或仅引用脚本库。