System.RegularExpressions in uses clause

Hi,

I try use RegularExpressions unit in my Web Core application like below:

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, XData.Web.Connection, Vcl.Controls, WEBLib.Login,
  XData.Web.Client, System.RegularExpressions;

but I get an error:

[Error] LoginFormFrm.pas(8): can't find unit "RegularExpressions"

In normal Delphi VCL application all is ok.

Why?

Regards

Sorry, at this moment the regular expressions unit has not yet been ported to the web RTL
You could directly use the JavaScript regular expression handling support by importing it via access through an ASM block

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

i.e.

  asm
    // JavaScript code dealing with regular expression here
  end;

Have a look at this Stack Overflow Answer: regex - How does regular expressions work in TMS WEB Core? - Stack Overflow


As of v1.3.0.0 of TMS WEB Core, you're able to use regular expressions in TMS WEB Core the same way as in VCL/FMX, but from the WEBLib.RegularExpressions unit instead of System.RegularExpressions.

So you can do the following and it works:

uses WEBLib.RegularExpressions;

...

function ValidateEmail(Email: string): Boolean;
const
  EmailPattern = '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$';
begin
  Result := TRegEx.IsMatch(Email, EmailPattern);
end;

If you're using an older version of TMS WEB Core, then you can also do regular expressions using JavaScript through the ASM code block in Delphi.

Here's an example using ASM code block:

function ValidateEmail(Email: string): Boolean;
const
  EmailPattern = '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$';
begin
  {$IFDEF PAS2JS}
    asm
      Result = (new RegExp(EmailPattern)).test(Email);
    end;
  {$ENDIF}
end;

Thx @Shaun_Roselt ... great job :slight_smile: