Inno Setup中字符串的正则表达式 [英] Regular expression for string in Inno Setup

查看:278
本文介绍了Inno Setup中字符串的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Inno设置工具(Windows OS)中

In Inno Setup tool (Windows OS)

InstallDir: string;   

我有一个字符串InstallDir,其中包含C:\-=[]\.,';

I have a string InstallDir which contains C:\-=[]\.,';

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

I want to set a regular expression pattern as below

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

例如: 应该是c:\< A至Z/a至z>或数字或_等(表示有效路径).

Ex: It should be c:\< A to Z / a to z > or number or _ and so on (means a valid path).

我在Inno Setup中找不到任何函数,这表明它支持字符串操作的正则表达式.

I could not find any function in Inno Setup, which tells it supports regular expression for string operations.

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

Can any body help me out to resolve this?

推荐答案

否,Inno Setup不支持正则表达式.

No, Inno Setup does not support regular expressions.

您也许可以为此调用PowerShell,但这太过分了.

You may be able to invoke PowerShell for that, but that's an overkill.

支票不需要正则表达式:

You do not need a regular expression for your check:

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设置6).

(The code requires Unicode version of Inno Setup, what you should use anyway and it is the only version as of current Inno Setup 6).

类似的问题:

  • Basic email validation within Inno Setup script
  • Wildcard characters in Inno Setup (test if there is any value after fixed string prefix)

这篇关于Inno Setup中字符串的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆