实现正则标签

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;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值