111,130
社区成员
发帖
与我相关
我的任务
分享string test = "<region name=oldslist col=1 row=2 order=asc>abcsadf </region> jfdsajf <region name=newslist col=4 row=10 order=desc>abcsadf </region>";
MatchCollection mc = Regex.Matches(test, @"<region[^>]*>", RegexOptions.IgnoreCase);
int z = 0;
foreach (Match m in mc)
{
richTextBox2.Text += "第" + ++z + "个region的属性:\n";
Match mList = Regex.Match(m.Value, @"(([^\s=]+)=([^\s>]+)\s*)+", RegexOptions.IgnoreCase);
for (int i = 0; i < mList.Groups[1].Captures.Count; i++)
{
richTextBox2.Text += "属性: " + mList.Groups[2].Captures[i].Value + " 值: " + mList.Groups[3].Captures[i].Value + "\n";
}
}string test = "<region name=oldslist col=1 row=2 order=asc>abcsadf </region> jfdsajf <region name=newslist col=4 row=10 order=desc>abcsadf </region>";
MatchCollection mc = Regex.Matches(test, @"<region[^>]*>", RegexOptions.IgnoreCase);
int z = 0;
foreach (Match m in mc)
{
richTextBox2.Text += "第" + ++z + "个region的属性:\n";
MatchCollection mcList = Regex.Matches(m.Value, @"([^\s=]+)=([^\s>]+)", RegexOptions.IgnoreCase);
foreach (Match mList in mcList)
{
richTextBox2.Text += "属性: " + mList.Groups[1].Value + " 值: " + mList.Groups[2].Value + "\n";
}
}string test = "<region name=oldslist col=1 row=2 order=asc>abcsadf </region> jfdsajf <region name=newslist col=4 row=10 order=desc>abcsadf </region>";
MatchCollection mc = Regex.Matches(test, @"<region[^>]*>", RegexOptions.IgnoreCase);
int z = 0;
foreach (Match m in mc)
{
richTextBox2.Text += "第" + ++z + "个region的属性:\n";
Match mList = Regex.Match(m.Value, @"<region\s+((?<pro>[^\s=]+)=(?<vla>\S+)\s*)+>", RegexOptions.IgnoreCase);
for (int i = 0; i < mList.Groups[1].Captures.Count; i++)
{
richTextBox2.Text += "属性: " + mList.Groups["pro"].Captures[i].Value + " 值: " + mList.Groups["vla"].Captures[i].Value + "\n";
}
}string test = "<region name=newslist col=4 row=10 order=desc>abcsadf </region> ";
Match m = Regex.Match(test, @"<region\s+((?<pro>[^\s=]+)=\S+\s*)+>", RegexOptions.IgnoreCase);
for(int i=0;i<m.Groups["pro"].Captures.Count;i++)
{
richTextBox2.Text += m.Groups["pro"].Captures[i].Value + "\n";
}List<string> list = new List<string>();
string test = "<region name=newslist col=4 row=10 order=desc>abcsadf </region> ";
Regex.Replace(test, @"(?<=<region\s+([^\s=<>]+=\S+\s*)*)[^\s=<>]+(?==)", delegate(Match m) { list.Add(m.Value); return ""; }, RegexOptions.IgnoreCase);
foreach (string s in list)
{
richTextBox2.Text += s + "\n";
}