Recent

Author Topic: RegExpr Error  (Read 1811 times)

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 365
RegExpr Error
« on: May 18, 2023, 12:23:32 am »
This program produces wrong output:

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode delphi }{$H+}
  4. uses
  5.   RegExpr;
  6. var
  7.   R:TRegExpr;
  8.  
  9. begin
  10.   R := TRegExpr.Create;
  11.   try
  12.     R.Expression:= '^[A-Z]{2}$';
  13.     writeln(R.Exec('US'));
  14.     writeln(R.Exec('USA'));
  15.   finally
  16.     R.Free;
  17.   end;
  18.   readln;
  19. end.    
  20.  

The output is

Code: Text  [Select][+][-]
  1. TRUE
  2. TRUE
  3.  

But it should be TRUE and then FALSE.

Is this a bug in TRegExpr?

Lazarus 2.2.7 (rev lazarus_2_2_6-1-gada7a90f86) FPC 3.2.3 aarch64-darwin-cocoa

« Last Edit: May 18, 2023, 12:25:07 am by Grahame Grieve »

dseligo

  • Hero Member
  • *****
  • Posts: 1219
Re: RegExpr Error
« Reply #1 on: May 18, 2023, 12:57:05 am »
I got
Code: Text  [Select][+][-]
  1. TRUE
  2. FALSE

under FPC 3.2.2 in both Windows 11 and Debian 11.



TRon

  • Hero Member
  • *****
  • Posts: 2503
Re: RegExpr Error
« Reply #2 on: May 18, 2023, 06:10:05 am »
I got the same result as dseligo with fpc 3.2.2 and trunk at Debian bookworm.

Could it be that your results are specific to 3.2.2 fixes ?

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 365
Re: RegExpr Error
« Reply #3 on: May 18, 2023, 06:56:05 am »
Perhaps it is. I will investigate. Thanks

paweld

  • Hero Member
  • *****
  • Posts: 991
Re: RegExpr Error
« Reply #4 on: May 18, 2023, 10:01:23 am »
Code: [Select]
TRUE
FALSE
Lazarus trunk + FPC 3.2.3 on Windows
Best regards / Pozdrawiam
paweld

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: RegExpr Error
« Reply #5 on: May 18, 2023, 11:29:43 am »
it is also OK for me on Mac OS Catalina 10.15 x86_64-darwin-cocoa Lazarus 2.2.6 fpc 3.2.2
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 365
Re: RegExpr Error
« Reply #6 on: May 18, 2023, 10:54:49 pm »
Also wrong for me on Lazarus 2.2.5 (rev lazarus_2_2_4-28-gcbedc5ddf0) FPC 3.2.3 aarch64-darwin-cocoa

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 365
Re: RegExpr Error
« Reply #7 on: May 18, 2023, 11:28:49 pm »
Well, it's a compiler bug, I think.

The program passes with FPC trunk, but if I copy the code for RegExpr from trunk to any older version of FPC, it fails.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: RegExpr Error
« Reply #8 on: May 19, 2023, 12:57:18 am »
hello,
try \Z instead of $
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 365
Re: RegExpr Error
« Reply #9 on: May 19, 2023, 01:11:51 am »
No difference. Which is good from my pov, since I'm not writing the regex- it's standard stuff.

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 365
Re: RegExpr Error
« Reply #10 on: May 19, 2023, 01:58:43 am »
Well, that presents me a challenge. I haven't yet found a version of Lazarus that doesn't access violate bringing up preferences while running on the trunk version of FPC... will keep trying

TRon

  • Hero Member
  • *****
  • Posts: 2503
Re: RegExpr Error
« Reply #11 on: May 19, 2023, 07:11:42 am »
@graham:
Wait, what ?

Are you trying to tell us that you are unable to run current Lazarus (*) (in combination with Free Pascal 3.2.2 fixes) on your setup ? I ask explicitly because in you first post you referred to Free Pascal as being version 3.2.3 (fixes). To my knowledge Lazarus trunk (2.3) always requires Free Pascal 3.3.1 (trunk) and by chance happens to work with older versions of FPC. As correctly stated by dsiders below: Lazarus trunk (2.3) always requires the latest stable Free Pascal (3.2.2 at the time of writing).

(*) You referred to Lazarus as 2.2.7 (fixes) which is to my my knowledge currently non existent so when you wrote Lazarus I assumed you meant trunk (2.3). Latest official release version of Lazarus is 2.2.6 (fixes being 2.2.7, trunk being 2.3) and for FPC that is 3.2.2 (fixes being 3.2.3, trunk being 3.3.1)
« Last Edit: May 19, 2023, 09:11:44 am by TRon »

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 365
Re: RegExpr Error
« Reply #12 on: May 19, 2023, 08:35:47 am »
I have tried stable, trunk and fixes of Lazarus with FPC 3.3.1 or trunk and all the Lazarus versions access violate when I try to open Lazarus preferences. I'm currently running "Lazarus 2.2.7 (rev lazarus_2_2_6-1-gada7a90f86) FPC 3.2.3 aarch64-darwin-cocoa" as the most recent thing I can get to run, but the regex is still broken for me. I'm kind of hoping someone else will take the time to figure out why preferences doesn't work and I'll try again in a few days.

dsiders

  • Hero Member
  • *****
  • Posts: 1078
Re: RegExpr Error
« Reply #13 on: May 19, 2023, 09:06:06 am »
To my knowledge Lazarus trunk (2.3) always requires Free Pascal 3.3.1 (trunk) and by chance happens to work with older versions of FPC.

And that is not correct. Lazarus trunk (2.3) has to build with the latest stable FPC release (3.2.2). Should work with 3.2.0... but everything I have at this point has 3.2.2. It's FPC 3.3.X that's the crap shoot, IMHO.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

TRon

  • Hero Member
  • *****
  • Posts: 2503
Re: RegExpr Error
« Reply #14 on: May 19, 2023, 09:10:01 am »
@dsiders:
Indeed, my apologies as you are right (I was incorrect there). Thank you for the correction. I adjusted my post accordingly.

 

TinyPortal © 2005-2018