Matlab字符串匹配,华为编程最给力

 function exist=wildcardl(pat)
%pat='http://*.huawei.com';->%pat='http://(\w+\.)+huawei.com'
 pat=strrep(pat,'*.','(\w+\.)+');
 pat=strcat(strcat('^',pat),'$');
 str=textread('data.txt','%s','delimiter','\n');
 result=regexp(str,pat,'start');
 exist=str(cellfun('length',result)==1,1);

 

 

function exist=wildcardr(pat)
  pat=strrep(pat,'.*','(\.\w+)+');
  pat=strcat(strcat('^',pat),'$');
  str=textread('data.txt','%s','delimiter','\n');
 result=regexp(str,pat,'start');
 exist=str(cellfun('length',result)==1,1);

 

function exist=wildcardlr(pat)
 %pat='http://*.huawei.com';->%pat='http://(\w+\.)+huawei.com'
 pat=strrep(pat,'*.','(\w+\.)+');
 pat=strrep(pat,'.*','(\.\w+)+');
 pat=strcat(strcat('^',pat),'$');
 str=textread('data.txt','%s','delimiter','\n');
 result=regexp(str,pat,'start');
 exist=str(cellfun('length',result)==1,1);
 

 

function exist=precise(pat)
str=textread('data.txt','%s','delimiter','\n');
% exist=length(cell2mat(regexp(str,pat,'start')));
result=regexp(str,pat,'start');
exist=str(cellfun('length',result)==1,1);

 

%expr is a directory ,if find expr
function exist=directory(expr)
str=textread('data.txt','%s','delimiter','\n');
exist=str(strcmp(expr,str));

 

%expr is a box
function exist=box(expr)
txt=textread('data.txt','%s','delimiter','\n');
expr=strcat(expr,'*');
exist=length(regexp(txt,expr,'start'));

你可能感兴趣的:(编程,function,matlab,华为)