Ben*_*uer 13 regex ms-access vba
我非常喜欢MS Access作为小型数据驱动应用程序的RAD-Tool.但是,作为.Net-Developer,我真正想念的一件事是正则表达式.在验证用户输入时,它们真的很方便.我真的不知道为什么微软没有把它们放在标准的VBA-Library中.
有没有办法在MS Access VBA中使用正则表达式?
Ben*_*enV 23
您可以通过添加对Microsoft VBScript正则表达式库的引用来使用VBScript正则表达式对象.
用法示例:
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
Run Code Online (Sandbox Code Playgroud)
资料来源:http://mark.biek.org/blog/2009/01/regular-expressions-in-vba/
归档时间: |
|
查看次数: |
24781 次 |
最近记录: |