RegEx新手
我有第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
答案 0 :(得分:2)
.Execute(R)(0)
是整个匹配项,用于查找需要调用.SubMatches
属性的子匹配项,即。 .Execute(R)(0).SubMatches(0)