110,536
社区成员
发帖
与我相关
我的任务
分享
string[] test = { "115h(1354(214g(dkfj(dkjf(xfds(dfs))))))", "115h(1354(214g(fdsf)214g(fdsf)))", "115h(1354(214g(fdsf)))", "115h(1354(214g()))", "115h()" };
Regex reg = new Regex(@"^[^()]+\((?!\))(?>\((?!\))(?<o>)|\)(?![^()]*\()(?<-o>)|[^()]*)*(?(o)(?!))\)$");
foreach (string s in test)
{
if (reg.IsMatch(s))
{
richTextBox2.Text += "源字符串:" + s + " 合法!\n";
}
else
{
richTextBox2.Text += "源字符串:" + s + " 不合法!\n";
}
}
/*---------输出-------
源字符串:115h(1354(214g(dkfj(dkjf(xfds(dfs)))))) 合法!
源字符串:115h(1354(214g(fdsf)214g(fdsf))) 不合法!
源字符串:115h(1354(214g(fdsf))) 合法!
源字符串:115h(1354(214g())) 不合法!
源字符串:115h() 不合法!
*/
string[] test = { "115h(1354(214g(dkfj(dkjf(xfds(dfs))))))", "115h(1354(214g(fdsf)214g(fdsf)))", "115h(1354(214g(fdsf)))", "115h(1354(214g()))" };
Regex reg = new Regex(@"^[^()]+\((?>\((?!\))(?<o>)|\)(?![^()]*\()(?<-o>)|[^()]*)*(?(o)(?!))\)$");
foreach (string s in test)
{
if (reg.IsMatch(s))
{
richTextBox2.Text += "源字符串:" + s + " 合法!\n";
}
else
{
richTextBox2.Text += "源字符串:" + s + " 不合法!\n";
}
}
/*---------输出-------
源字符串:115h(1354(214g(dkfj(dkjf(xfds(dfs)))))) 合法!
源字符串:115h(1354(214g(fdsf)214g(fdsf))) 不合法!
源字符串:115h(1354(214g(fdsf))) 合法!
源字符串:115h(1354(214g())) 不合法!
*/
string[] test = { "115h(1354(214g(dkfj(dkjf(xfds(dfs))))))", "115h(1354(214g(fdsf)214g(fdsf)))", "115h(1354(214g(fdsf)))" };
Regex reg = new Regex(@"^[^()]+\((?>\((?<o>)|\)(?![^()]*\()(?<-o>)|[^()]*)*(?(o)(?!))\)$");
foreach (string s in test)
{
if (reg.IsMatch(s))
{
richTextBox2.Text += "源字符串:" + s + " 合法!\n";
}
else
{
richTextBox2.Text += "源字符串:" + s + " 不合法!\n";
}
}
/*---------输出-------
源字符串:115h(1354(214g(dkfj(dkjf(xfds(dfs)))))) 合法!
源字符串:115h(1354(214g(fdsf)214g(fdsf))) 不合法!
源字符串:115h(1354(214g(fdsf))) 合法!
*/