• excel VBA构造正则函数(双参数)


    Function zhengze(ze As String, Rng As Range)
        Set regx = CreateObject("vbscript.regexp")

    With regx

      .Global = True

      .Pattern = ze '写正则表达式
      Set mat = .Execute(Rng)
      For Each mg In mat
         If .test(Rng) Then
            zhengze = mg
         Else
            zhengze = 0
      'Set mat = .Execute(value)

     
          

          'cells 单元格 读取单元格内容,将内容写入单元格,将变量rg的值输入到c列的n行

        End If
       Next

    End With
    End Function

    ------------------------------------------------------------------------------------------------------------------------------------

    if外置,无匹配值则返回空值,单引号后为注释内容,可忽略

    -------------------------------------------------------------------------------------------------------------------------------------

    Function zhengze(ze As String, Rng As Range)
        Set regx = CreateObject("vbscript.regexp")
        

    With regx

      .Global = True

      .Pattern = ze '写正则表达式
      Set mat = .Execute(Rng)
      If .test(Rng) Then '无匹配值则为空
        
        For Each mg In mat
          'If .test(Rng) Then
            zhengze = mg
         
      'Set mat = .Execute(value)


          'cells 单元格 读取单元格内容,将内容写入单元格,将变量rg的值输入到c列的n行

         'End If
        Next
       Else
         zhengze = " "
       End If
    End With
    End Function

    ------------------------------------------------------------------------------------------------------------------------------------

    匹配结果多个时,合并显示

    ==================================================================================

    Function zhengze(ze As String, Rng As Range)
        Set regx = CreateObject("vbscript.regexp")
        

    With regx

      .Global = True

      .Pattern = ze '写正则表达式
      Set mat = .Execute(Rng)
      If .test(Rng) Then '无匹配值则为空|匹配成功执行循环
        Dim m As String
        If mat.Count > 1 Then   '为多个匹配结果则合并显示,否则显示当前值
          For Each mg In mat
          
            m = m & mg & "|"    '循环并合并匹配结果
              
          Next
          zhengze = m
        Else
          zhengze = mat(0).value    '参数存储是一个列表形式,不能直接=号取值,必须用列表固有取值方式
        End If
          
          
       Else
         zhengze = " "
       End If
    End With
    End Function

    红尘往事,一切随风!
  • 相关阅读:
    jedis异常:Could not get a resource from the pool
    redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resourc
    【redis】常见JedisConnectionException异常分析
    JAVA,字符串首字母转大写(高效率)
    Type handler was null on parameter mapping for property 'products'. It was either not specified and/or could not be found for the javaType / jdbcType combination specified
    java读取blob,clob转换为字符串
    mybatis对blob属性数据的处理
    mybatis读取oracle中blob
    jpa2.x的getOne()/findOne()/findById()的区别及使用
    IDEA如何导入导出出settings配置文件
  • 原文地址:https://www.cnblogs.com/xwenwu/p/11760016.html
Copyright © 2020-2023  润新知