Inno Setup 中字符串的正则表达式

问题描述 投票:0回答:1

在 Inno Setup 工具中(Windows 操作系统)

InstallDir: string;   

我有一个字符串

InstallDir
,其中包含
C:\-=[]\.,';

我想设置如下正则表达式模式

^([a-zA-Z]:)\\([0-9a-zA-Z_\\\s\.\-\(\)]*)$

例如: 应该是

c:\
<
A
Z
/
a
z
> 或数字或
_
等等(表示有效路径)。

我在 Inno Setup 中找不到任何函数,说明它支持正则表达式进行字符串操作。

有人可以帮我解决这个问题吗?

regex inno-setup pascalscript
1个回答
6
投票

不,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;

(代码需要 Inno Setup 的 Unicode 版本,无论如何你都应该使用它,它是当前 Inno Setup 6 的唯一版本)。


类似问题:

© www.soinside.com 2019 - 2024. All rights reserved.