在 Inno Setup 工具(Windows 操作系统)中
InstallDir: string;
Run Code Online (Sandbox Code Playgroud)
我有一个字符串InstallDir,其中包含 C:\-=[]\.,';
我想设置一个正则表达式模式如下
^([a-zA-Z]:)\\([0-9a-zA-Z_\\\s\.\-\(\)]*)$
Run Code Online (Sandbox Code Playgroud)
例如:它应该是 c:\< A to Z / a to z > 或 number 或 _ 等(表示有效路径)。
我在 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;
Run Code Online (Sandbox Code Playgroud)
(该代码需要 Inno Setup 的 Unicode 版本,无论如何您都应该使用它,并且它是当前 Inno Setup 6 的唯一版本)。
类似问题: