Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-12

What's the correct way to use TRegexEngine?

19 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hi,

The correct way to use RegEx is like I'm showing below? (I saw this code in bugtracker)

uses
  RegEx;
procedure TForm1.Button1Click(Sender: TObject);
var
  VRegEx: TRegexEngine;
  VErrorCode: TRegexError;
  VOffset, VErrorPos, VMatchPos: Integer;
begin
  VRegEx := TRegexEngine.Create('[0-9]');
  try
    try
      VErrorPos := 0;
      VMatchPos := 0;
      VErrorCode := recNone;
      if VRegEx.Parse(VErrorPos, VErrorCode) then
      begin
        VOffset := 1; //<<<------ I use 1 or 0 here? :/
        if VRegEx.MatchString('ABC123', VMatchPos, VOffset) then
          ShowMessage('Match')
        else
          ShowMessage('No Match');
      end
      else
        ShowMessage('Parse Failed');
    except
      on E: Exception do
        ShowMessage('RegEx ERROR: ' + E.Message);
    end;
  finally
    VRegEx.Free;
  end;
end;

Thx.

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Mark Morgan Lloyd
to silvioprog
silvioprog wrote
Hi, The correct way to use RegEx is like I'm showing below? (I saw this code in bugtracker)
   regex1 := TRegExpr.Create;
   regex1.Expression := pattern1;
   with regex1 do begin
     if Exec(test1) then begin
       WriteLn('match');
     end else
       WriteLn('no match');
Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

silvioprog
to Mark Morgan Lloyd

2011/12/22 Mark Morgan Lloyd :

Show quoted text 19 lines
silvioprog wrote: > > Hi, > > The correct way to use RegEx is like I'm showing below? (I saw this > code in bugtracker) ?regex1 := TRegExpr.Create; ?regex1.Expression := pattern1; ?with regex1 do begin ? ?if Exec(test1) then begin ? ? ?WriteLn('match'); ? ?end else ? ? ?WriteLn('no match'); -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk

I can not use the LCL.

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Graeme Geldenhuys
to silvioprog
silvioprog wrote
I can not use the LCL.

What has regex and LCL have to do with each other? Why do you think regex requires LCL? I have many apps that use regex, and none of the depend on LCL.

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Mark Morgan Lloyd
to Graeme Geldenhuys: What has regex and LCL have to do with each other? Why do you think regex requires LCL? I…
Graeme Geldenhuys wrote
On 22 December 2011 21:25, silvioprog wrote:>> I can not use the LCL. What has regex and LCL have to do with each other? Why do you thinkregex requires LCL? I have many apps that use regex, and none of thedepend on LCL.

I was, in retrospect, slightly out of order in using an example for Sorokin rather than the "old" one. But I too fail to see what the OP is grounding his concern on, unless he assumes that write() and writeln() are part of the LCL.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

silvioprog
to Graeme Geldenhuys: What has regex and LCL have to do with each other? Why do you think regex requires LCL? I…

2011/12/23 Graeme Geldenhuys :

Show quoted text 7 lines
On 22 December 2011 21:25, silvioprog wrote: > > I can not use the LCL. What has regex and LCL have to do with each other? Why do you think regex requires LCL? I have many apps that use regex, and none of the depend on LCL.

The regex that he indicated uses LCL yes! >> "[LCL]SynRegExpr.TRegExpr".

The regex that I'm using belongs to FCL. >> "[FCL]RegEx.TRegexEngine".

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Sven Barth
to silvioprog
silvioprog wrote 13 lines
2011/12/23 Graeme Geldenhuys: > On 22 December 2011 21:25, silvioprog wrote: >> >> I can not use the LCL. > > What has regex and LCL have to do with each other? Why do you think > regex requires LCL? I have many apps that use regex, and none of the > depend on LCL. The regex that he indicated uses LCL yes!>> "[LCL]SynRegExpr.TRegExpr". The regex that I'm using belongs to FCL.>> "[FCL]RegEx.TRegexEngine".

TRegExpr (unit RegExpr) is also part of FCL in 2.7.1 since some weeks/months.

Regards,
Sven

Reply by email

silvioprog
to Sven Barth

2011/12/23 Sven Barth :

Show quoted text 25 lines
Am 23.12.2011 10:29, schrieb silvioprog: > > 2011/12/23 Graeme Geldenhuys: >> >> On 22 December 2011 21:25, silvioprog ?wrote: >>> >>> >>> I can not use the LCL. >> >> >> What has regex and LCL have to do with each other? Why do you think >> regex requires LCL? I have many apps that use regex, and none of the >> depend on LCL. > > > The regex that he indicated uses LCL yes!>> ?"[LCL]SynRegExpr.TRegExpr". > > The regex that I'm using belongs to FCL.>> ?"[FCL]RegEx.TRegexEngine". > TRegExpr (unit RegExpr) is also part of FCL in 2.7.1 since some weeks/months. Regards, Sven

I'm using FPC 2.4.4. :(

My RegExpr unit: http://pastebin.com/N2ARAcx1

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Graeme Geldenhuys
to silvioprog: 2011/12/23 Graeme Geldenhuys : The regex that he indicated uses LCL yes! >>…
silvioprog wrote
The regex that he indicated uses LCL yes! >> "[LCL]SynRegExpr.TRegExpr".

Look inside that unit. It is the TRegExpr library originally created by Andrey V. Sorokin for Delphi. It has no dependency on LCL units at all, only the RTL. Simply copy that unit into your project, give it a better name and use it. It is a lot more powerful and feature complete, compare to what comes with any released FPC.

The regex that I'm using belongs to FCL. >> "[FCL]RegEx.TRegexEngine".

As far as I remember the regex unit included in FCL (released versions of FPC) is pretty limited in what it can do. I would not use that for any regex project. Use the TRegExpr library instead.

Only recently did someone include a more powerful regex engine in FPC trunk - but I don't know how that one compares to the one from Andrey V. Sorokin.

Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

silvioprog
to Graeme Geldenhuys

2011/12/23 Graeme Geldenhuys :

Show quoted text 27 lines
On 23 December 2011 11:29, silvioprog wrote: > > The regex that he indicated uses LCL yes! >> "[LCL]SynRegExpr.TRegExpr". Look inside that unit. It is the TRegExpr library originally created by Andrey V. Sorokin for Delphi. It has no dependency on LCL units at all, only the RTL. Simply copy that unit into your project, give it a better name and use it. It is a lot more powerful and feature complete, compare to what comes with any released FPC. > > The regex that I'm using belongs to FCL. >> "[FCL]RegEx.TRegexEngine". As far as I remember the regex unit included in FCL (released versions of FPC) is pretty limited in what it can do. I would not use that for any regex project. Use the TRegExpr library instead. Only recently did someone include a more powerful regex engine in FPC trunk - but I don't know how that one compares to the one from Andrey V. Sorokin. -- Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

I saw. Although TRegExpr be in the folder of Lazarus, it don't depend of LCL. Perfect! :)

Thanks for your helpful. ^^

Silvio Cl?cio ==================================== Site - <silvioprog.com.br> LazSolutions - <code.google.com/p/lazsolutions> ====================================

Reply by email

Sven Barth
to Graeme Geldenhuys: Look inside that unit. It is the TRegExpr library originally created by Andrey V. Sorokin…
Graeme Geldenhuys wrote 12 lines
> > The regex that I'm using belongs to FCL.>> "[FCL]RegEx.TRegexEngine". As far as I remember the regex unit included in FCL (released versions of FPC) is pretty limited in what it can do. I would not use that for any regex project. Use the TRegExpr library instead. Only recently did someone include a more powerful regex engine in FPC trunk - but I don't know how that one compares to the one from Andrey V. Sorokin.

It is the Sorokin one that was included, see here: http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&revision=18891

Regards,
Sven

Reply by email

Mark Morgan Lloyd
to Marco van de Voort
Marco van de Voort wrote 6 lines
On Fri, Dec 23, 2011 at 10:47:23AM +0100, Sven Barth wrote: >> The regex that I'm using belongs to FCL.>> "[FCL]RegEx.TRegexEngine". > TRegExpr (unit RegExpr) is also part of FCL in 2.7.1 since some > weeks/months. August 29th, pulled up into 2.5.1/2.6.0 about a month later.

With the caveat that fixes might get applied to one or the other. For example I see that Ludo's fix for
http://mantis.freepascal.org/view.php?id=20806 (plus at least one alignment issue) is in FPC 19759 but not in Lazarus 34371.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Sven Barth
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 13 lines
Marco van de Voort wrote: > On Fri, Dec 23, 2011 at 10:47:23AM +0100, Sven Barth wrote: >>> The regex that I'm using belongs to FCL.>> "[FCL]RegEx.TRegexEngine". >> TRegExpr (unit RegExpr) is also part of FCL in 2.7.1 since some >> weeks/months. > > August 29th, pulled up into 2.5.1/2.6.0 about a month later. With the caveat that fixes might get applied to one or the other. For example I see that Ludo's fix for http://mantis.freepascal.org/view.php?id=20806 (plus at least one alignment issue) is in FPC 19759 but not in Lazarus 34371.

Maybe 2.4.4 support for Lazarus (trunk) will be dropped once 2.6.0 is released and then the variant distributed with Lazarus can be removed.

Regards,
Sven

Reply by email

Mark Morgan Lloyd
to Sven Barth
Sven Barth wrote 17 lines
Am 23.12.2011 15:13, schrieb Mark Morgan Lloyd: > Marco van de Voort wrote: >> On Fri, Dec 23, 2011 at 10:47:23AM +0100, Sven Barth wrote: >>>> The regex that I'm using belongs to FCL.>> "[FCL]RegEx.TRegexEngine". >>> TRegExpr (unit RegExpr) is also part of FCL in 2.7.1 since some >>> weeks/months. >> >> August 29th, pulled up into 2.5.1/2.6.0 about a month later. > > With the caveat that fixes might get applied to one or the other. For > example I see that Ludo's fix for > http://mantis.freepascal.org/view.php?id=20806 (plus at least one > alignment issue) is in FPC 19759 but not in Lazarus 34371. > Maybe 2.4.4 support for Lazarus (trunk) will be dropped once 2.6.0 is released and then the variant distributed with Lazarus can be removed.

Better done sooner than later since there's very little divergence between the two variants so far- a couple of alignment/widestring fixes in the FPC one, and an extra block of definitions at the start of the Lazarus/Synedit one.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Marco van de Voort
to Sven Barth: Maybe 2.4.4 support for Lazarus (trunk) will be dropped once 2.6.0 is released and then…
Sven Barth wrote 7 lines
> With the caveat that fixes might get applied to one or the other. For > example I see that Ludo's fix for > http://mantis.freepascal.org/view.php?id=20806 (plus at least one > alignment issue) is in FPC 19759 but not in Lazarus 34371. Maybe 2.4.4 support for Lazarus (trunk) will be dropped once 2.6.0 is released and then the variant distributed with Lazarus can be removed.

When 2.6.0 is out, and since 2.4.2+ etc support deprecated fine, I would simply deprecate the lazarus sorokin unit.

That gives a signal to users to convert using the FPC one, while not forcing them to do it immediately (or if they are still using 2.4.2/2.4.4, which probably will be packaged with distributions for a while)

Reply by email

William Oliveira Ferreira
to Marco van de Voort

I think the first step is to add FPC 2.6 to the Installer package (at least on Windows). On Linux, I always download the "recomended" version: http://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20i386%20DEB/Lazarus%200.9.30.2/ as you can see, it?s offered two versions of FPC and that?s the version i?ll use...
________________________________
William de Oliveira Ferreira
Bacharel em Sistemas de Informa??o

2011/12/23 Marco van de Voort

Show quoted text 24 lines
On Fri, Dec 23, 2011 at 04:20:23PM +0100, Sven Barth wrote: > > With the caveat that fixes might get applied to one or the other. For > > example I see that Ludo's fix for > > http://mantis.freepascal.org/view.php?id=20806 (plus at least one > > alignment issue) is in FPC 19759 but not in Lazarus 34371. > > Maybe 2.4.4 support for Lazarus (trunk) will be dropped once 2.6.0 is > released and then the variant distributed with Lazarus can be removed. When 2.6.0 is out, and since 2.4.2+ etc support deprecated fine, I would simply deprecate the lazarus sorokin unit. That gives a signal to users to convert using the FPC one, while not forcing them to do it immediately (or if they are still using 2.4.2/2.4.4, which probably will be packaged with distributions for a while) -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111223/f073baf6/attachment.html>

Reply by email