我绝对喜欢MS Access作为小范围数据驱动应用程序的RAD工具。但作为.NET开发人员,我真正怀念的一件事就是正则表达式。在验证用户输入时,它们确实派上了用场。我真的不知道为什么微软不把这些放在标准的VBA库中。
在MS Access VBA中有没有使用正则表达式的方法?
发布于 2010-09-22 23:22:15
您可以通过添加对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/
发布于 2010-09-22 23:22:11
你可以使用CreateObject("vbscript.regexp")
或者直接引用脚本库。
https://stackoverflow.com/questions/3770672
复制相似问题