excel vba中利用正则表达式提取id后的数字和name后的汉字应该怎么写

<camera id="111" name="汉字"/>
2025-04-04 03:48:00
推荐回答(2个)
回答(1):

假设你的上面的字段在sheet1的A1单元格

Sub test()
Dim regx As Object
Set regx = CreateObject("vbscript.regexp")
Dim str As String
str = Sheet1.Range("a1").Value
Dim s
With regx
    .Global = True
    .Pattern = "\d+|[一-龥]+"
    Set matc = .Execute(str)
    For Each s In matc
        i = i + 1
        Sheet1.Cells(i, 2) = s
    Next
End With
End Sub

结果放在sheet1的B1,B2单元格。

如下图所示:

回答(2):

用不着vba吧,函数就可以提出来了,多放点数据上来看下特征给你写