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

Graeme Geldenhuys graemeg.lists at gmail.com
Mon Dec 1 12:38:25 CET 2008


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
      writeln('match')
    else
      writeln('failed');
  end;
  r.Free;
  sl.Free;

--------------[  output ]-------------------
match
failed
failed
failed
failed



Based on the syntax documentation from TRegEx (which I believe 'regex'
unit closely represents) and looking at the syntax comments inside the
regex.pp unit, it should match the following...

Examples:
  foob.*r     matchs strings like 'foobar', 'foobalkjdflkj9r' and 'foobr'

http://regexpstudio.com/TRegExpr/Help/regexp_syntax.html
  About halfway down the page...



even trying a filter as follows, match NO items in the stringlist???

  r := TRegexEngine.Create('th');

I expected it to match items '4th' and '5th', but it didn't.


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list