using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions; //
/// <summary>
/// Cls_Regex 的摘要说明
/// </summary>
namespace Cls_Regex
{
public class Cls_Regex
{
//前三个为使用前必须初始化的参数
public string InStr = ""; //输入的源字符串
public string LName = ""; //标签名称
public int LCount = 0; //标签参数个数
public int len = 0; //标签个数
public Cls_Regex()
{
}
//获得源字符串中标签的个数
public int FucGetLen()
{
string label = @"/[" + LName.ToString() + "(//|(//d|//w)+){" + LCount.ToString() + "}//|" + LName.ToString() + "]";
MatchCollection mc = Regex.Matches(InStr, label);
len = mc.Count;
return len;
}
//获得标签与参数
//返回值为二维数组
public string[,] FucGetLabel()
{
string label = @"/[" + LName.ToString() + "(//|(//d|//w)+){" + LCount.ToString() + "}//|" + LName.ToString() + "]";
string str1 = "";
FucGetLen();
string[,] str3 = new string[len, LCount + 1];
int i = 0, j = 0;
MatchCollection mc1 = Regex.Matches(InStr, label);
foreach (Match m1 in mc1)
{
str3[i, 0] = m1.Value.ToString();
str1 = @"(/|(/d|/w)+){" + LCount.ToString() + "}//|";
MatchCollection mc2 = Regex.Matches(m1.Value.ToString(), str1);
foreach (Match m2 in mc2)
{
m2.Value.ToString();
string[] str2 = Regex.Split(m2.Value.ToString(), @"/|");
for (j = 1; j <= LCount; j++)
{
str3[i, j] = str2[j].ToString();
}
}
i++;
}
return str3;
}
}
}