8
我正在使用Access VBA解析正则表达式的字符串。这是我的正则表达式功能:vba积极lookahead太贪婪
regexSearch("^.+(?=[ _-]+mp)", "153 - MP 13.61 to MP 17.65")
我期待得到:
Function regexSearch(pattern As String, source As String) As String
Dim re As RegExp
Dim matches As MatchCollection
Dim match As match
Set re = New RegExp
re.IgnoreCase = True
re.pattern = pattern
Set matches = re.Execute(source)
If matches.Count > 0 Then
regexSearch = matches(0).Value
Else
regexSearch = ""
End If
End Function
当我测试它
153
,因为这和第一个实例之间唯一的字符'MP'是在前视中指定的类中的那些。
,但我实际的返回值是:
153 - MP 13.61 to
为什么捕捉到第二个“MP”?
这解决了这个问题。 – sigil
很高兴听到这个印记。 –
+1很好地完成。 – brettdj