직장에서 두 개의 문자열이 일치하는 문제가 발생했습니다. 요구 사항은 다음과 같습니다. 각 문자열에는 최대 하나의 *가 포함되며, ?는 모든 길이의 문자열을 나타내는 무한한 수의
*를 가질 수 있습니다.
문자를 나타내며 두 가지 충돌이 필요합니다
Javascript를 사용하여 다음과 같이 코드를 구현합니다.
[javascript]
function checkMarchX()
{
var str1 = document.getElementById('str1').value;
var str2 = document.getElementById('str2').value;
var str1XPosition = str1.indexOf('*');
var str2XPosition = str2.indexOf('*');
if(str1XPosition!=-1 && str2XPosition!=-1)//两者twitter含有*
{
var position = str1XPosition>str2XPosition;//success
if( position!=0)
{
var patbeforeStr1 = str1.substring(0,position);
var patbeforeStr2 = str2.substring(0,position);
if(checkMarchQ(patbeforeStr1,patbeforeStr2))
{
//alert(str1+'与'+str2+"前半부분분冲突");
//然后对应后半부분분담进行测试
var str1XBackPosition = str1.length-str1XPosition-1;
var str2XBackPosition = str2.length-str2XPosition-1;
var backposition = str1XBackPosition>str2XBackPosition?str2XBackPosition:str1XBackPosition;
if (backposition==0)
{
Alert(str1+'与'+str2+"冲突");
}
else
{
var patbackStr1 = str1.sub 문자열(str1.length-backposition,str1.length);
var patbackStr2 = str2.substring(str2.length-backposition,str2.length);
if(checkMarchQ(patbackStr1,patbackStr2))
{
경고(str1+''+ str2+"입력");
}
}
}
}
else
{
//alert(str1+'与'+str2+"앞부분분할");
var str1XBackPosition = str1.length-str1XPosition-1;
var str2XBackPosition = str2.length-str2XPosition-1;
var backposition = str1XBackPosition>str2XBackPosition?str2XBackPosition:str1XBackPosition;
if (backposition==0)
{
Alert(str1+'与'+str2+"冲突"); else { var patbackstr1 = str1.substring (str1.length-backposition, str1.length);
var patbackStr2 = str2.substring(str2.length-backposition,str2.length);
if(checkMarchQ(patbackStr1,patbackStr2))
{
경고(str1+'与'+str2+"冲突") ;
}
}
}
}
else if((str1XPosition==-1 && str2XPosition !=-1)||(str1XPosition!=-1 && str2XPosition==-1) )//유신한 글자가 있습니다*
{
var strX = str1XPosition==-1?str2:str1;//含有*字符串
var strNoX = str 1XPosition==-1? str1:str2;//不含*字符串
if (strX.length-1
var position = strX.indexOf('*');
if(position==0)
{
//alert(str1+'与'+str2+"前半부분분冲突");
var backposition = strX.length-position-1;
if (backposition==0)
{
Alert(str1+'与'+str2+"冲突");
}
else
{
var patbackStr1 = str1.substring(str1.length-backposition,str1.length);
var patbackStr2 = str2.substring(str2.length-backposition,str2.length);
if(checkMarchQ(patbackStr1,patbackStr2))
{
경고(str1+''+ str2+"입력");
}
}
}
else
{
var patbeforeStr1 = str1.substring(0,position);
var patbeforeStr2 = str2.substring(0,position);
if(checkMarchQ(patbeforeStr1,patbeforeStr2))
{
//alert(str1+'与'+str2+"前半부분분류");
var backposition = strX.length-position-1;
if (backposition==0)
{
경고(str1+'与'+str2+"冲突");
}
else
{
var patbackStr1 = str1.substring(str1.length-backposition,str1.length);
var patbackStr2 = str2.substring(str2.length-backposition,str2.length);
if(checkMarchQ(patbackStr1,patbackStr2))
{
경고(str1+'与'+str2+"冲突");
}
}
~ +str2+"충돌")
if(str1.length= =str2.length)
{ if(str1.substr (i,1)!='?' && str2.substr( i,1)!='?')
> ~ ~ > ~ 확인