Match method returns inconsistent result #56

Closed
opened 2020-03-18 07:13:55 +00:00 by rchastain · 3 comments
rchastain commented 2020-03-18 07:13:55 +00:00 (Migrated from github.com)

Hello!
Here is my code:

uses
  SysUtils, FLRE;

procedure MatchTest(const APattern, ASubject: TFLRERawByteString);
var
  e: TFLRE;
  c: TFLRECaptures;
begin
  e := TFLRE.Create(APattern, []);
  try
    WriteLn(APattern:10, ASubject:10, e.Match(ASubject, c):10);
  finally
    e.Free;
  end;
end;

begin
  MatchTest('\d+', '123');
  MatchTest('\d+', '123.');
  MatchTest('\d+', '.123');
end.

And the result:

       \d+       123      TRUE
       \d+      123.      TRUE
       \d+      .123     FALSE

Is it the expected behaviour? I would have expected the same result for line 2 and line 3 (both FALSE, or both TRUE).

By the way, I intend to write a tutorial for regular expressions with FLRE. That's why I come here to bore you. :)

Regards.

Roland

Hello! Here is my code: ``` uses SysUtils, FLRE; procedure MatchTest(const APattern, ASubject: TFLRERawByteString); var e: TFLRE; c: TFLRECaptures; begin e := TFLRE.Create(APattern, []); try WriteLn(APattern:10, ASubject:10, e.Match(ASubject, c):10); finally e.Free; end; end; begin MatchTest('\d+', '123'); MatchTest('\d+', '123.'); MatchTest('\d+', '.123'); end. ``` And the result: ``` \d+ 123 TRUE \d+ 123. TRUE \d+ .123 FALSE ``` Is it the expected behaviour? I would have expected the same result for line 2 and line 3 (both FALSE, or both TRUE). By the way, I intend to write a tutorial for regular expressions with FLRE. That's why I come here to bore you. :) Regards. Roland
BeRo1985 commented 2020-03-18 07:41:53 +00:00 (Migrated from github.com)

Yes, it is the expected behaviour. What do you want, is MatchAll (or Match + multiple MatchNext calls) but not Match.

Yes, it is the expected behaviour. What do you want, is MatchAll (or Match + multiple MatchNext calls) but not Match.
BeRo1985 commented 2020-03-18 07:51:28 +00:00 (Migrated from github.com)

And when 123. should be also false, you should use anchors and write \d+$ :-)

^ = Begin anchor
$ = End anchor

And when `123.` should be also false, you should use anchors and write `\d+$` :-) `^` = Begin anchor `$` = End anchor
rchastain commented 2020-03-18 07:54:46 +00:00 (Migrated from github.com)

OK, thank you.

OK, thank you.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
BeRo1985/flre#56
No description provided.