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, s: Integer;
- b, e: Boolean;
- begin
- Match := '';
- 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;
- SetLength(TSA, r);
- Hi := High(TSA);
- b := (expr[1] = ignore);
- e := (expr[_Right] = ignore);
- if (Hi > -1) then
- case (Hi = 0) of
- False:
- begin
- case b of
- True:
- begin
- Left := 1;
- _Right := Left;
- s := 0;
- end;
- False:
- begin
- Left := Pos(TSA[0], Str);
- _Right := (Left + Length(TSA[0]));
- s := 1;
- end;
- end;
- if ((Hi > (s - 1)) and (Left > 0)) then
- begin
- case Sensitive of
- True:
- for i := s 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 := s to Hi do
- begin
- p := LastPos(TSA[i], str);
- if (p > _Right) then
- _Right := (P + Length(TSA[i]))
- else
- Exit;
- end;
- end;
- if e then
- Match := Copy(Str, Left, ((Length(str) - Left) + 1))
- else
- Match := Copy(Str, Left, (_Right - Left));
- Result := True;
- end;
- end;
- True:
- begin
- P := Pos(TSA[0], Str);
- Result := (P > 0);
- if Result then
- case b of
- True:
- case e of
- False: match := Copy(Str, 1, ((Length(TSA[0]) + P) - 1));
- True: match := Copy(Str, 1, Length(Str));
- end;
- False:
- case e of
- False: match := Copy(Str, P, Length(TSA[0]));
- True: match := Copy(Str, P, Length(Str) - Length(TSA[0]));
- end;
- end;
- end;
- end;
- end;
- end;
- var
- str, expression, match: string;
- begin
- ClearDebug;
- expression := 'Test*it*work*';
- 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