在 Inno Setup 工具(Windows 操作系统)中
InstallDir: string;
我有一个字符串InstallDir
,其中包含C:\-=[]\.,';
我想设置如下正则表达式模式
^([a-zA-Z]:)\\([0-9a-zA-Z_\\\s\.\-\(\)]*)$
例如: 它应该是 c:\< A to Z/a to z > 或数字或 _ 等(表示有效路径)。
我在Inno Setup中找不到任何函数,这表明它支持字符串操作的正则表达式。
有人可以帮我解决这个问题吗?
最佳答案
不,Inno Setup 不支持正则表达式。
您也许可以为此调用 PowerShell,但这太过分了。
您的检查不需要正则表达式:
function IsPathValid(Path: string): Boolean;
var
I: Integer;
begin
Path := Uppercase(Path);
Result :=
(Length(Path) >= 3) and
(Path[1] >= 'A') and (Path[1] <= 'Z') and
(Path[2] = ':') and
(Path[3] = '\');
if Result then
begin
for I := 3 to Length(Path) do
begin
case Path[I] of
'0'..'9', 'A'..'Z', '\', ' ', '.', '-', '(', ')':
else
begin
Result := False;
Break;
end;
end;
end;
end;
end;
(代码 requires Unicode version of Inno Setup ,无论如何你都应该使用它,它是当前 Inno Setup 6 的唯一版本)。
<小时/>类似问题:
关于regex - Inno Setup 中字符串的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47263968/