Форум: "Основная";
Текущий архив: 2002.01.28;
Скачать: [xml.tar.bz2];
ВнизКак найти в заданном тексте, сочетания символов, которые подходят заданной схеме? Найти похожие ветки
← →
marat_from_tomsk (2002-01-08 05:08) [5]Рекомендую для использования как раз позволяет определить
соотвествует ли входная строка требуемому образцу
(* (c) 1996, tomsk, guards, marat@tts.tomsk.su, ap@tts.tomsk.su *)
unit MatchUnits;
interface
uses Classes;
const
c1 = "*";
c2 = "?";
function Match(str, pattern: string): boolean;
implementation
function RMatch(str, pattern: string; i, j: integer): boolean;
var
k: integer;
f: boolean;
begin
if pattern = "" then begin result := true; exit;
end;
while true do begin
if (i > Length(str)) and (j > Length(pattern)) then begin
result := true;
exit;
end else if j > Length(pattern) then begin
result := false;
exit;
end else if pattern[j] = c1 then begin
k := i;
if j = Length(pattern) then begin
result := true;
exit;
end else begin
while true do begin
f := Rmatch(str, pattern, k, j + 1);
if (f or (k > Length(str))) then begin
result := f;
exit;
end;
inc(k);
end;
end;
end else if i > Length(str) then begin
result := false;
exit;
end else if ((pattern[j] = c2) and (i <= Length(str)) or (pattern[j] = str[i])) then begin
inc(i);
inc(j);
end else begin
result := false;
exit;
end;
end;
end;
function Match(str, pattern: string): boolean;
var
f: boolean;
begin
f := RMatch(str, pattern, 1, 1);
result := f;
end;
end.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2002.01.28;
Скачать: [xml.tar.bz2];
Память: 0.44 MB
Время: 0.004 c