Advertisement

在VBA中进行正则表达式分组时使用SubMatches进行操作

阅读量:

SubMatches:获取匹配到的字符串的所有分组

复制代码
    Sub 测试()
    Dim my_str$, mt, mh, sub_str$
    
    Set reg = CreateObject("vbscript.regexp")  '定义一个正则对象
    
    my_str = "我人民币大写:123656.00。小写:123654.03 " & _
             "中介人民币大写:800.36公司日丰人民币大写:36659.32.日韩地晶上 "
    
    With reg
        .Pattern = "(人民币大写:)(\d+\.[0-9]{1,3})"  '正则表达式      
        .Global = True  '匹配出所有符合条件的字符       
        .IgnoreCase = False  '不忽略大小写        
        .MultiLine = True  '多行模式
        
        Set mh = .Execute(my_str)  '执行匹配
    End With
    
    For i = 0 To mh.Count - 1
        sub_str = sub_str & mh(i).SubMatches

全部评论 (0)

还没有任何评论哟~