【问题标题】:Regular Expressions in MS Access VBA?MS Access VBA中的正则表达式?
【发布时间】:2011-04-15 19:13:55
【问题描述】:

我绝对喜欢将 MS Access 作为小范围数据驱动应用程序的 RAD 工具。但作为 .Net 开发人员,我真正怀念的一件事是正则表达式。在验证用户输入时,它们真的派上用场了。我真的不知道为什么微软没有把这些放在标准的 VBA-Library 中。

有没有办法在 MS Access VBA 中使用正则表达式?

【问题讨论】:

    标签: regex ms-access vba


    【解决方案1】:

    您可以通过添加对 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/

    【讨论】:

    【解决方案2】:

    您可以使用CreateObject("vbscript.regexp") 或仅引用脚本库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 2016-01-13
      • 1970-01-01
      • 2019-01-27
      • 2020-08-31
      • 1970-01-01
      相关资源
      最近更新 更多