如何编写代码来识别模式是否仅在字符串内部?和 * 在 autoit 中。 例子
function("string","pattern",1 = sensitive\0 = no sensitive)
function("hello whale","?ello *",1) = true return 1
function("hello whale","?ello w?al*",1) = true return 1
...
问题是我无法使用正则表达式,因为字符被视为表达式。我需要编写尽可能快的代码,因为我必须进行很多比较。谢谢
示例:
Func iswm($string,$pattern,$s)
if Not $s then
$string = StringLower($string)
$pattern = StringLower($pattern)
EndIf
If StringRegExp($string,"^" & StringReplace(stringreplace($pattern,"*","(.*)") & "$","?","(.)")) = 1 Then return 1
EndFunc
问题是 $pattern 可能包含我不想仅评估 * 和 ? 的字符
我认为,使用 REGEX 模式效果很好(
function2
),但如果出于某种原因你不能使用它们,
function
可以与你的通配符
?
和
*
一起使用:
; function("string","pattern",1 = sensitive\0 = no sensitive)
ConsoleWrite(function("Hello whaLe", "?ello *", 1) & @CRLF)
ConsoleWrite(function("hEllo whaLe", "?ello w?al*", 1) & @CRLF)
ConsoleWrite(function2("Hello Whale", ".ello .*", 1) & @CRLF)
ConsoleWrite(function2("Hello whAle", "^.ello w.al.*$", 1) & @CRLF)
Func function($string, $pattern, $case) ; using your wildcards
$pattern = StringReplace($pattern, "?", ".")
StringReplace($pattern, "*", ".*")
If $case = 1 Then $case = "(?i)"
$y = StringRegExp($string, $case & $pattern, 0)
; ConsoleWrite("DBG: " & $string & " / " & $pattern & " / " & $case & " = " & $y & @CRLF)
Return $y
EndFunc ;==>function
Func function2($string, $pattern, $case) ; using standard REGEX wildcards
If $case = 1 Then $case = "(?i)"
$y = StringRegExp($string, $case & "^" & $pattern & "$", 0)
; ConsoleWrite("DBG: " & $string & " / " & $pattern & " / " & $case & " = " & $y & @CRLF)
Return $y
EndFunc ;==>function2