Sto usando Access VBA per analizzare una stringa con regex. Ecco la mia funzione regex:vba lookahead positivo è troppo goloso
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
Quando ho prova con:
regexSearch("^.+(?=[ _-]+mp)", "153 - MP 13.61 to MP 17.65")
mi aspetto di ottenere:
153
perché gli unici personaggi tra questo e la prima istanza di 'MP' sono quelli nella classe specificata nel lookahead.
ma il mio effettivo valore restituito è:
153 - MP 13.61 to
Perché è catturare fino al secondo 'MP'?
che ha risolto esso. – sigil
Buono a sentire quel sigillo. –
+1 ben fatto. – brettdj