从我已经拥有的东西上剪下来;
s = "SELECT * FROM Books WHERE BookID" & parseSarg("11,22,33")
使用;
Public Function parseSarg(str As String) As String
Dim re As Object: Set re = CreateObject("vbscript.regexp")
re.Global = True
Select Case True
'//is number
Case reTest(re, "^\d+$", str): parseSarg = " = " & str
'//is number-number
Case reTest(re, "^\d+-\d+$", str): parseSarg = " BETWEEN " & Replace$(str, "-", " AND ")
'//is number,number[,number]
Case reTest(re, "^\d+(?:,\d+)*$", str): parseSarg = " IN (" & str & ")"
'//is >number
Case reTest(re, "^>\s*\d+$", str): parseSarg = " >" & Mid$(str, 2)
Case Else
parseSarg = " = 0 AND 1=0"
End Select
End Function
Function reTest(re As Object, pattern As String, value As String) As Boolean
re.pattern = pattern
reTest = re.Test(value)
End Function