Recent

Author Topic: Problem with the TRegExpr Library  (Read 7109 times)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Problem with the TRegExpr Library
« on: July 31, 2011, 12:22:59 pm »
Hi all,
When I try to split strings, get the following error. Any idea how can i overcome this error.
Thanks.

TRegExpr(exec): ExecNext without Exec[Pos]

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Problem with the TRegExpr Library
« Reply #1 on: July 31, 2011, 12:44:18 pm »
My crystal ball says you didn't call Exec.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Problem with the TRegExpr Library
« Reply #2 on: July 31, 2011, 01:44:59 pm »

I tried with the Match and it works normal but when I add the Split syntax, the same error occurs. Thanks

      re:=TRegExpr.Create;
      try
        re.Expression := 'example expression';
        if re.Exec(tmpstr.Text) then
        repeat
//          re.Split(tmpstr.Text, ostr);
//          Memo2.Lines.Add(ostr[1]);
          Memo2.Lines.Add(re.Match[0]);
        until not re.ExecNext;
      finally
        re.Free;
      end;

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Problem with the TRegExpr Library
« Reply #3 on: August 01, 2011, 10:38:25 am »
Bump

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Problem with the TRegExpr Library
« Reply #4 on: August 05, 2011, 08:52:49 pm »
Bump
Ow, my head  :D

Finally had some time to investigate this.
You shouldn't call ExecNext because Split already parses the complete text.
ostr contains all returned lines.
Instead of only adding ostr[1], add all lines to the memo box that were returned.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

 

TinyPortal © 2005-2018