Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function StrMatchesEx(ignore: Char; s, str: string; sensitive: Boolean; var position: Integer): string;
- var
- t: TStringArray;
- h, i, l, p, f: Integer;
- d: string;
- begin
- position := 0;
- Result := '';
- l := Length(s);
- if ((l > 0) and not (l > Length(str))) then
- begin
- d := StringOfChar(ignore, 1);
- t := Explode(d, s);
- h := High(t);
- f := Pos(t[0], str);
- l := (f + Length(t[0]));
- if ((h > 0) and (f > 0)) then
- begin
- case sensitive of
- True:
- for i := 1 to h do
- begin
- p := PosEx(t[i], str, l);
- if (p > 0) then
- l := (p + Length(t[i]))
- else
- Exit;
- end;
- False:
- for i := 1 to h do
- begin
- p := LastPos(t[i], str);
- if (p > l) then
- l := (p + Length(t[i]))
- else
- Exit;
- end;
- end;
- position := f;
- Result := Copy(str, f, (l - f));
- end;
- end;
- end;
- function StrMatches(ignore: Char; s, str: string; sensitive: Boolean): string;
- var
- t: TStringArray;
- h, i, l, p, f: Integer;
- d: string;
- begin
- Result := '';
- l := Length(s);
- if ((l > 0) and not (l > Length(str))) then
- begin
- d := StringOfChar(ignore, 1);
- t := Explode(d, s);
- h := High(t);
- f := Pos(t[0], str);
- l := (f + Length(t[0]));
- if ((h > 0) and (f > 0)) then
- begin
- case sensitive of
- True:
- for i := 1 to h do
- begin
- p := PosEx(t[i], str, l);
- if (p > 0) then
- l := (p + Length(t[i]))
- else
- Exit;
- end;
- False:
- for i := 1 to h do
- begin
- p := LastPos(t[i], str);
- if (p > l) then
- l := (p + Length(t[i]))
- else
- Exit;
- end;
- end;
- Result := Copy(str, f, (l - f));
- end;
- end;
- end;
- var
- position: Integer;
- str, expr: string;
- begin
- str := 'hello world world world, cheese!';
- ClearDebug;
- expr := StrMatches('*', 'hello*world', str, False);
- if (expr <> '') then
- WriteLn('"' + expr + '"');
- expr := StrMatchesEx('*', 'hello*world', str, False, position);
- if (expr <> '') then
- WriteLn('"' + expr + '" @' + IntToStr(position));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement