{*******************************************************}
{                                                       }
{       Pascal Script Source File                       }
{       Run by RemObjects Pascal Script in CnWizards    }
{                                                       }
{       Generated by CnPack IDE Wizards                 }
{                                                       }
{*******************************************************}

program RegExprDemo;

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RegExpr;

procedure CheckPhoneNumber(S: string);
begin
  if ExecRegExpr ('^\s*\d{3}-(\d{2}-\d{2}|\d{4})\s*$', S) then
    Writeln(S + ' => ' + 'Phone number is Ok')
  else
    Writeln(S + ' => ' + 'Error in the Phone field');
end;

procedure SearchPhoneNumber(S: string);
begin
  if ExecRegExpr ('\d{3}-(\d{2}-\d{2}|\d{4})', S) then
    Writeln(S + ' => ' + 'Phone number found')
  else
    Writeln(S + ' => ' + 'There is no phone number in the Phone field');
end;

begin
  CheckPhoneNumber('555-1234');
  CheckPhoneNumber('555-55-22');
  CheckPhoneNumber('55A5-55-22');

  SearchPhoneNumber('345-33-55');
  SearchPhoneNumber('Phone: 345-33-55');

  Writeln(ReplaceRegExpr('(block|var)\s*\(\s*([^ ]*)\s*\)\s*',
    'block( test1)', 'def "$1" value "$2"', True));
  Writeln(ReplaceRegExpr('(block|var)\s*\(\s*([^ ]*)\s*\)\s*',
    'var( test1)', 'def "$1" value "$2"', False));
end.

