Icon View Thread

The following is the text of the current message along with any replies.
Messages 21 to 27 of 27 total
Thread Regular Expressions - How to?
Mon, Sep 12 2016 7:55 AMPermanent Link

Matthew Jones

erickengelke wrote:

> I'd also be tempted to put a check digit at the end of the number.

If this is a new system, that would be ideal. If it is working with an
existing one, it will depend on that, but hopefully that already has
such a scheme.  Might be worth flagging "invalid" ones separately.

--

Matthew Jones
Mon, Sep 12 2016 1:19 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 9/10/2016 2:36 PM, Trinione wrote:
> Thank you very much for the direction. I have implemented and testing various scenarios.
> I am wondering if Tim plans on including this as part of EWB?

I have no doubt Tim would want to include this eventually - issue always
is time.

However using external files does not really result in any penalties for
your code : it's all JS at the end. You do have to ship an extra file
and do your own testing for function.

EWB "native" solution would essentially building the external structures
for the RegExp (see WebDom) so you can call it in EWB but at the end
they would still be external calls like this.

Raul

Mon, Sep 12 2016 3:18 PMPermanent Link

Trinione

Raul wrote:
<< However using external files does not really result in any penalties for
your code : it's all JS at the end. You do have to ship an extra file
and do your own testing for function. >>

I like the compiling into one file with EWB. That way I have less installed files to worry about. Erick mentioned the ability to include these files so once I get his book later on this week, I shall know how to do so.


Thanks to all for the suggestions.

Never thought I would say this - but the RegEx solution was the easiest for me. Seeing the TStringList, PosEx and string manipulation actually sent me to me 'Oh Gawd No!' scary programmer moment. Smile
Mon, Sep 12 2016 4:20 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 9/12/2016 3:18 PM, Trinione wrote:
> Never thought I would say this - but the RegEx solution was the easiest for me. Seeing the TStringList, PosEx and string manipulation actually sent me to me 'Oh Gawd No!' scary programmer moment. Smile

RegEx in right circumstance is a great tool to have and flexibility is
unmatched - just change the expression.

String parsing has its place as well - if your input is fixed format
then string parsing will usually outperform regex.

Raul
Wed, Sep 14 2016 1:49 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< Which leads me to ask this: How can RegExp be included in EWB?

Adding via the External Function is ok, but not having to do this and an external file is preferred. >>

Here's the "native" version without external JS (I've added the RegExp external interface to the WebDOM unit):

type

  external TRegExpResult emit RegExpResult = class
     public
        { Properties }
        property matches[index: Integer]: String read; default;
        property index: Integer read;
        property input: String read;
        property length: Integer read;
     end;

  external TRegExp emit RegExp = class
     public
        constructor Create(const pattern: String; const flags: String='');
        { Properties }
        property lastIndex: Integer read write;
        property flags: String read;
        property global: Boolean read;
        property ignoreCase: Boolean read;
        property multiline: Boolean read;
        property source: String read;
        property sticky: Boolean read;
        property unicode: Boolean read;
        { Methods }
        function exec(const str: String): TRegExpResult;
        function test(const str: String): Boolean;
        function toString: String;
     end;

implementation

function RunRegExec(const Expr: String; const Txt: String): array of String;
var
  TempRegExp: TRegExp;
  TempResult: TRegExpResult;
begin
  SetLength(Result,0);
  TempRegExp:=TRegExp.Create(Expr,'gi');
  TempResult:=TempRegExp.exec(Txt);
  while (TempResult <> nil) do
     begin
     SetLength(Result,Length(Result)+1);
     Result[Length(Result)-1]:=TempResult[0];
     TempResult:=TempRegExp.exec(Txt);
     end;
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  regResultArray : array of string;
  i:integer;
begin
  regResultArray := RunRegExec('\S+\:\S+' ,'This is a sample string with AID:123456 in it and CID:789012.');

  MultiLineEdit1.Lines.Add('Regex found num of matches  =' +inttostr(Length(regResultArray)));
  for i:= 0 to Length(regResultArray) - 1 do
     MultiLineEdit1.Lines.Add(regResultArray[i]);
end;

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Sep 14 2016 6:03 PMPermanent Link

Trinione

Tim Young [Elevate Software] wrote:
<< (I've added the RegExp external interface to the WebDOM unit) >>

Thanks Tim!

When you say you have 'added it to the WebDOM unit, do you mean you have added it to EWB itself for future versions? And, if not, shall you?
Mon, Sep 19 2016 7:20 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< When you say you have 'added it to the WebDOM unit, do you mean you have added it to EWB itself for future versions? >>

Yes, the WebDOM unit is part of EWB.

Tim Young
Elevate Software
www.elevatesoft.com
Previous PagePage 3 of 3
Jump to Page:  1 2 3
Image