下面是一个示例数据帧。
0 1 2 3 4
0 0.0 13.00 4.50 30.0 0.0,13.0
1 0.0 13.00 4.75 30.0 0.0,13.0
2 0.0 13.00 5.00 30.0 0.0,13.0
3 0.0 13.00 5.25 30.0 0.0,13.0
4 0.0 13.00 5.50 30.0 0.0,13.0
5 0.0 13.00 5.75 0.0 0.0,13.0
6 0.0 13.00 6.00 30.0 0.0,13.0
7 1.0 13.25 0.00 30.0 0.0,13.25
8 1.0 13.25 0.25 0.0 0.0,13.25
9 1.0 13.25 0.50 30.0 0.0,13.25
10 1.0 13.25 0.75 30.0 0.0,13.25
11 2.0 13.25 1.00 30.0 0.0,13.25
12 2.0 …Run Code Online (Sandbox Code Playgroud) 例如,我尝试将“This 9 is 8 a 77 6 test”中第二次出现的数字替换为“hello”。
所以我希望结果是“This 9 is hello a 77 6 test”。
相反,我得到的是“hellohello test”。
我在用着:
=RegexReplace("This 9 is 8 a 77 6 test","(?:\D*(\d+)){2}","hello")
Run Code Online (Sandbox Code Playgroud)
其中 RegexReplace 定义如下:
Function RegexReplace(text As String, pattern As String, replace As String)
Static re As Object
If re Is Nothing Then
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.MultiLine = True
End If
re.IgnoreCase = True
re.pattern = pattern
RegexReplace = re.replace(text, replace)
Set re = Nothing
End Function
Run Code Online (Sandbox Code Playgroud)