String "check me please"
Regular (check) (me)

those. about MATCH, one should go in match[1] , the other in match[2] , it says that the regular does not find anything at all, here’s a sample:

 procedure TForm1.Button1Click(Sender: TObject); var test1:string; t:TRegExpr; begin test1:='check me please'; t:=TRegExpr.Create; try t.Expression:='(check)(me)'; t.InputString:=test1; if t.Exec then begin repeat showmessage('match[1]= '+t.Match[1]+' match[2]= '+t.Match[2]); until not t.ExecNext; end else showmessage('а нет ничего'); finally t.Free; end; end; 

what's wrong?

  • one
    And how (check)(me) (without a space between words) should catch check me please (with a space) - alexlz

1 answer 1

So try to figure it out:

 test1:=' check me '; ... t.Expression:=' (.*?) (.*?) '; ... 

here it is necessary to indicate not the words you want to pull out, but how the parts that you need are separated. In this case, the words in the original have gaps on the sides, and on this basis matches are sought.

In your example it will be like this:

 t.Expression:='(.*?) (.*?) '; 

or so:

 t.Expression:='(.*?) (.*?) please'; 

but in general on the Internet a lot of information on this issue

Ps. about accurate tearing: true too

 t.Expression:='(check) (me)'; 

you just had to put a space between (check) and (me)

  • and what will it do? This is not exact matching, this is just a tearing out of words, obviously not an option, but I have seen this “information”. - Smash
  • aha, here to the account of gaps it yes, understood. - Smash