111,125
社区成员
发帖
与我相关
我的任务
分享//递归方法
private void getNesting(string src, Regex reg, List<string> list)
{
MatchCollection mc = reg.Matches(src);
foreach (Match m in mc)
{
list.Add(m.Value);
src = m.Value.Remove(m.Value.Length - 1, 1);
if (reg.IsMatch(src))
{
getNesting(src, reg, list);
}
}
}
//调用
string test = "【Get=【变量1】/code.php?rand=【Rand=10,500】】";
List<string> list = new List<string>();
Regex reg = new Regex(@"(?i)【(?>[^【】]+|【(?<o>)|】(?<-o>))*(?(o)(?!))】", RegexOptions.Compiled);
getNesting(test, reg, list);
foreach (string s in list)
{
richTextBox2.Text += s + "\n";
}
//输出
【Get=【变量1】/code.php?rand=【Rand=10,500】】
【变量1】
【Rand=10,500】
说了那么多,还不知道你究竟想怎么用,只能是全部取出来了