gpt4 book ai didi

正则表达式模式不完全存在

转载 作者:行者123 更新时间:2023-12-04 20:15:17 26 4
gpt4 key购买 nike

正则表达式新手

我有第 1 行的单元格,例如:

This That Other [Stuff I want to Keep]

我想
Suff I want to Keep

该模式给出
[Stuff I want to Keep]

我不知道如何去掉括号,即 []
我可以用 vba 做到这一点,但尝试一些新的东西

谢谢
Sub Test()
Dim ws As Worksheet
Dim R As Range, Rng As Range
Dim i As Long, LC As Long

Set ws = ThisWorkbook.Sheets("RegistrationData_Prepped")
LC = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
Set Rng = ws.Range("A1").Resize(1, LC)

With CreateObject("VBScript.RegExp")
.Pattern = "\[([^\]]+)\]"

For Each R In Rng
If .Test(R.Value) Then
R(, 3) = .Execute(R)(0)
End If
Next
End With
End Sub

最佳答案

.Execute(R)(0)是整个匹配,要找到您需要调用的子匹配 .SubMatches属性(property),即.Execute(R)(0).SubMatches(0)

关于正则表达式模式不完全存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28118950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com