MS Access VBA中的正则表达式? [英] Regular Expressions in MS Access VBA?

查看:134
本文介绍了MS Access VBA中的正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝对喜欢MS Access作为适用于小型数据驱动应用程序的RAD-Tool.但是,作为.Net-Developer我真正想念的一件事是正则表达式.在验证用户输入时,它们确实派上了用场.我真的不知道为什么微软没有将它们放在标准的VBA库中.

I definitely like MS Access as an RAD-Tool for small-scope data-driven applications. But one thing I really miss as a .Net-Developer is Regular Expressions. They really come in handy when validating user input. I really do not know why Microsoft did not put these in the standard VBA-Library.

是否可以在MS Access VBA中使用正则表达式?

Is there a way to use Regular Expressions in MS Access VBA?

推荐答案

您可以使用 VBScript正则表达式对象,添加了对Microsoft VBScript正则表达式库的引用.

You can use the VBScript Regex Object by adding a reference to the Microsoft VBScript Regular Expressions library.

示例用法:

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/

这篇关于MS Access VBA中的正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆