delphi常用正则表达式

来源:互联网 发布:js里的on是什么意思 编辑:程序博客网 时间:2024/06/03 14:51
function checkanystr(str: string; mytype: integer):Boolean;
var
  myper: TPerlRegEx;
  areg: string;
begin
  Result := False;
  if str = '' then Exit;

  myper := TPerlRegEx.Create(nil);

  try

  myper.Subject := str;
  case mytype of
  //email
   0:areg := '\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*';
   //整数
   1:areg := '^-?[1-9]\d*$';
   //浮点数
   3:areg := '^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$';
   //国内电话
   4:areg := '\d{3}-\d{8}|\d{4}-\d{7}';
   //数字字符下划线
   5:areg := '^\w+$';
   //腾讯qq
   6:areg := '[1-9][0-9]{4,}';
   //国内邮编
   7:areg := '[1-9]\d{5}(?!\d)';
   //身份证
   8:areg := '\d{15}|\d{18}';
   //ip地址
   9:areg := '\d+\.\d+\.\d+\.\d+';
   //网址
   10:areg := '[a-zA-z]+://[^\s]* ';
   //账号,字母开头,5-15位字符数字下划线
   11:areg := '^[a-zA-Z][a-zA-Z0-9_]{4,15}$';
  end;
  myper.RegEx :=areg ;

  Result := myper.Match;

  finally

  FreeAndNil(myper);

 end;

end;
0 0