[fpc-pascal] regex unit doesn't find matches???

Joost van der Sluis joost at cnoc.nl
Mon Dec 1 12:59:57 CET 2008


Op maandag 01-12-2008 om 13:38 uur [tijdzone +0200], schreef Graeme
Geldenhuys:
> Hi,
> 
> I'm using the following regular expression:   'foob.*r'
> Calling MatchString() against each of the items in the stringlist, I
> expected it to match 3 items. Instead it only matches the first item
> and fails all the rest.  Why???
> 
> 
> --------------[  source code ]-------------------
>   sl := TStringList.Create;
>   sl.Add('1st foobr Item');
>   sl.Add('2nd Item');
>   sl.Add('3rd Item');
>   sl.Add('4th foobaoeuaor Item');
>   sl.Add('5th foobar Item');
> 
>   r := TRegexEngine.Create('foob.*r');
>   x := 0;
>   y := 0;
>   for i := 0 to sl.Count-1 do
>   begin
>     if r.MatchString(sl.Strings[i], x, y) then

Because of the offset y you give it? Try to reset it to 0 within the
loop.

Joost




More information about the fpc-pascal mailing list