Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function StrMatches(Expr, Str: string; Ignore: Char; Sensitive: Boolean; var Match: String): Boolean;
- var
- TSA: TStrArray;
- Hi, i, _Right, P, Left, r: Integer;
- begin
- Result := False;
- _Right := Length(Expr);
- if ((_Right > 0) and not (_Right > Length(Str))) then
- begin
- TSA := Explode(ignore, expr);
- Hi := High(TSA);
- r := 0;
- for i := 0 to Hi do
- if (Length(TSA[i]) > 0) then
- begin
- TSA[r] := TSA[i];
- r := (r + 1);
- end;
- Hi := High(TSA);
- if (Hi > -1) then
- case (Hi = 0) of
- False:
- begin
- Left := Pos(TSA[0], Str);
- _Right := (Left + Length(TSA[0]));
- if ((Hi > 0) and (Left > 0)) then
- begin
- case Sensitive of
- True:
- for i := 1 to Hi do
- begin
- p := PosEx(TSA[i], Str, _Right);
- if (p > 0) then
- _Right := (P + Length(TSA[i]))
- else
- Exit;
- end;
- False:
- for i := 1 to Hi do
- begin
- p := LastPos(TSA[i], str);
- if (p > _Right) then
- _Right := (P + Length(TSA[i]))
- else
- Exit;
- end;
- end;
- Match := Copy(Str, Left, (_Right - Left));
- Result := True;
- end;
- end;
- True:
- begin
- P := Pos(TSA[0], Str);
- Result := (P > 0);
- if Result then
- match := Copy(Str, P, Length(TSA[0]));
- end;
- end;
- end;
- end;
- var
- str, expression, match: string;
- begin
- expression := 'Test';
- str := 'This is Test, it works!';
- if StrMatches(expression, str, '*', True, match) then
- WriteLn(match);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement