excel VBA构造正则函数(单参数)

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

With regx

  .Global = True

  .Pattern = "d{4}-d{2}-d{2}" '写正则表达式
  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

红尘往事,一切随风!
原文地址:https://www.cnblogs.com/xwenwu/p/11759860.html