public static string [] g_findTemplet(string regStr,string info)
{
Regex reg = new Regex(regStr,RegexOptions.IgnoreCase|RegexOptions.Multiline);
MatchCollection Allmatch = reg.Matches(info);
//string[] result;
string tmpStr = "";
try
{
if(Allmatch.Count>0)
{
foreach(Match amatch in Allmatch)
{
if(tmpStr.Trim()=="")
{
tmpStr = amatch.Value.Trim();
}
else
{
tmpStr = tmpStr + "," + amatch.Value.Trim();
}
}
string[] result = tmpStr.Split(',');
Array.Sort(result,0,result.Length);
Array.Reverse(result,0,result.Length);
return result;
}
else
{
string[] result = {};
return result;
}
}
catch
{
string[] result = {};
return result;
}
}这个函数,我第一次用
string[] findTemplet = global_function.g_findTemplet(@"<\$([^<>$]+)\$>",tInfo);
int loop = findTemplet.Length;
foreach(string str in findTemplet)
{
tInfo = global_function.g_processTemplet(tInfo,str.Trim());
//temp = temp + str;
}
findTemplet这个数组生成的没问题,但是执行到g_processTemplet,由于这个函数里又调用了一次g_findTemplet(@"[\$([^[]$]+)\$]",tInfo),就说错误!未处理的“System.ArgumentException”类型的异常出现在 system.dll 中。
其他信息: 正在分析“[\$([^[]$]+)\$]”- ) 过多。请问这个是为什么呀谢谢了

解决方案 »

  1.   

    >>>但是执行到g_processTemplet,由于这个函数里又调用了一次g_findTemplet(@"[\$([^[]$]+)\$]",tInfo),where is this g_processTemplet?? in tInfo = global_function.g_processTemplet(tInfo,str.Trim());which parameter is the regular expression pattern? make sure it has balanced "(" and ")"
      

  2.   

    我又实验过了,发现我不能调用2次g_findTemplet函数,一调用就出错请问为什么啊。
    string[] findTemplet = global_function.g_findTemplet(@"<\$([^<>$]+)\$>",tInfo);
    string[] findTemplet1 = global_function.g_findTemplet(@"[\$([^[]$]+)\$]",rInfo2);
    这样就出了
    未处理的“System.ArgumentException”类型的异常出现在 system.dll 中。
    其他信息: 正在分析“[\$([^[]$]+)\$]”- ) 过多。
    错误
      

  3.   

    要匹配如[$asdasd$]之类的吗?
    需要将[]转义
    \[\$([^[]$]+)\$\]