Beispiel #1
0
        /// <summary>
        /// 通过Match方式解析表达式
        /// </summary>
        /// <param name="context">
        /// </param>
        protected virtual void EvaluateMatch(RegexContex context)
        {
            context.Matches.Clear();
            context.Groups.Clear();
            var coll = this.regex.Matches(context.Content);

            if (coll.Count == 0)
            {
                return;
            }

            var groupCount = 0;

            foreach (Match match in coll)
            {
                context.Matches.Add(match.Value);
                this.GetMaxInt(match.Groups.Count, ref groupCount);
            }

            for (var i = 0; i < groupCount; i++)
            {
                var groupItems =
                    (from Match match in coll where match.Groups[i] != null select match.Groups[i].Value).ToList();
                context.Groups.Add(i, groupItems);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 解析表达式
        /// </summary>
        /// <param name="contex">
        /// </param>
        public void Evaluate(RegexContex contex)
        {
            if (contex == null)
            {
                throw new ArgumentNullException("contex");
            }

            switch (contex.Operator)
            {
                case RegexOperator.Matches:
                    this.EvaluateMatch(contex);
                    break;
                case RegexOperator.Replace:
                    this.EvaluateReplace(contex);
                    break;
                default:
                    throw new ArgumentException();
            }
        }
Beispiel #3
0
        /// <summary>
        /// 解析表达式
        /// </summary>
        /// <param name="contex">
        /// </param>
        public void Evaluate(RegexContex contex)
        {
            if (contex == null)
            {
                throw new ArgumentNullException("contex");
            }

            switch (contex.Operator)
            {
            case RegexOperator.Matches:
                this.EvaluateMatch(contex);
                break;

            case RegexOperator.Replace:
                this.EvaluateReplace(contex);
                break;

            default:
                throw new ArgumentException();
            }
        }
Beispiel #4
0
 /// <summary>
 /// 通过Replace方式替换表达式内容
 /// </summary>
 /// <param name="contex">
 /// </param>
 protected virtual void EvaluateReplace(RegexContex contex)
 {
     contex.Content = this.regex.Replace(contex.Content, contex.Replacement);
 }
Beispiel #5
0
        /// <summary>
        /// 通过Match方式解析表达式
        /// </summary>
        /// <param name="context">
        /// </param>
        protected virtual void EvaluateMatch(RegexContex context)
        {
            context.Matches.Clear();
            context.Groups.Clear();
            var coll = this.regex.Matches(context.Content);
            if (coll.Count == 0)
            {
                return;
            }

            var groupCount = 0;
            foreach (Match match in coll)
            {
                context.Matches.Add(match.Value);
                this.GetMaxInt(match.Groups.Count, ref groupCount);
            }

            for (var i = 0; i < groupCount; i++)
            {
                var groupItems =
                    (from Match match in coll where match.Groups[i] != null select match.Groups[i].Value).ToList();
                context.Groups.Add(i, groupItems);
            }
        }
Beispiel #6
0
 /// <summary>
 /// 通过Replace方式替换表达式内容
 /// </summary>
 /// <param name="contex">
 /// </param>
 protected virtual void EvaluateReplace(RegexContex contex)
 {
     contex.Content = this.regex.Replace(contex.Content, contex.Replacement);
 }