zoukankan      html  css  js  c++  java
  • VBA 正则表达式

    '正则
    Function RegExp(text As String, reg As String) As String
      
        Dim mRegExp As Object       '正则表达式对象
        Dim mMatches As Object      '匹配字符串集合对象
        Dim mMatch As Object        '匹配字符串
        
        RegExp = ""
        
        Set mRegExp = CreateObject("Vbscript.Regexp")
        With mRegExp
            .Global = True                              'True表示匹配所有, False表示仅匹配第一个符合项
            .IgnoreCase = True                          'True表示不区分大小写, False表示区分大小写
            .Pattern = reg  '匹配字符模式 ".*[款].*[号][\d]+[、](.*)"
            Set mMatches = .Execute(text)   '执行正则查找,返回所有匹配结果的集合,若未找到,则为空
            
            For Each mMatch In mMatches
                If (Not mMatch.SubMatches(0) = "") Then
                    RegExp = Trim(mMatch.SubMatches(0))
                End If
            Next
        End With
        
        Set mRegExp = Nothing
        Set mMatches = Nothing
    End Function

  • 相关阅读:
    HashMap代码示例
    ArrayList代码示例
    ArrayList&LinkedList&Map&Arrays
    Calendar日历小程序
    System & Runtime &Math
    基本类型的封装类
    开发规范
    P1607 [USACO09FEB]庙会班车Fair Shuttle
    P2869 [USACO07DEC]美食的食草动物Gourmet Grazers
    Set,Multiset,Iterator(迭代器)详解
  • 原文地址:https://www.cnblogs.com/grj001/p/12225442.html
Copyright © 2011-2022 走看看