C#RegexHelper正则表达式帮助类

/*
 * 由SharpDevelop创建。
 * 用户: gyc
 * 日期: 2020-11-12
 * 时间: 8:18
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Wesun.AssemblyInStock
{
    public class RegexHelper
    {
        ///


        /// 匹配返回List
        ///

        /// 正则表达式
        /// 匹配文本
        ///
        public List RegexForList(string a_strPattern,string a_txtContext)
        {
            List l_listString = new List();
            l_listString.Clear();
            
            Regex l_regResult = new Regex(a_strPattern,RegexOptions.IgnoreCase);
            MatchCollection matches = l_regResult.Matches(a_txtContext);
            foreach(Match item in matches)
            {
                l_listString.Add(item.Value);
            }
            return l_listString;
        }
        
        ///
        /// 匹配返回Dictionary
        ///

        /// 正则表达式
        /// 匹配文本
        ///
        public Dictionary RegexForDictionary(string a_strPattern,string a_txtContext)
        {
            Dictionary l_dicResult = new Dictionary();
            l_dicResult.Clear();
            
            Regex reg_Power = new Regex(@a_strPattern,RegexOptions.IgnoreCase);
            MatchCollection matches = reg_Power.Matches(a_txtContext);
            foreach(Match item in matches)
            {
                if(l_dicResult.ContainsKey(item.Value)==false)
                {
                    l_dicResult.Add(item.Value,item.Value);
                }
            }
            return l_dicResult;
        }
        
        ///
        /// 匹配返回bool
        ///

        /// 正则表达式
        /// 匹配文本
        ///
        public bool RegexForBool(string a_strPattern,string a_txtContext)
        {
            Regex reg = new Regex(@a_strPattern,RegexOptions.IgnoreCase);
            Match match = reg.Match(a_txtContext);
            return match.Success;
        }
        
        ///
        /// 匹配返回string
        ///

        /// 正则表达式
        /// 匹配文本
        ///
        public string RegexForString(string a_strPattern,string a_txtContext)
        {
            Regex l_reg = new Regex(@a_strPattern,RegexOptions.IgnoreCase);
            MatchCollection matches_Type = l_reg.Matches(a_txtContext);
            foreach(Match item in matches_Type)
            {
                return item.Value;
            }
            return "";
        }
    }
}

你可能感兴趣的:(底层库(工具,通用类),正则表达式)