Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for string in Inno Setup

In Inno Setup tool (Windows OS)

InstallDir: string;   

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\.\-\(\)]*)$

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

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?

like image 426
user1239973 Avatar asked Nov 13 '17 12:11

user1239973


1 Answers

No, Inno Setup does not support regular expressions.

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;

(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).


Similar questions:

  • Basic email validation within Inno Setup script
  • Wildcard characters in Inno Setup (test if there is any value after fixed string prefix)
like image 79
Martin Prikryl Avatar answered Nov 11 '22 08:11

Martin Prikryl