예제 #1
0
파일: REGEX.cs 프로젝트: ingted/CLRUDF
 public static string regexFun(string target, string expr, object g, regexAct ra, string replStr, int replCnt, int replStart, ref MatchCollection o, int capID) {
     int gn = g is int ? Int32.Parse(g.ToString()) : 0;
     if (capID < 0) { capID = 0; }
     Regex regex = new Regex(expr, RegexOptions.Multiline | RegexOptions.IgnoreCase);
     try {
         switch (ra) {
             case regexAct.Match:
                 var varMatch = regex.Match(target);
                 if (!varMatch.Success) {
                     return null;
                 } else if (g is String && Array.Exists(regex.GetGroupNames(), gpnm => (gpnm == g.ToString()))) {
                     return varMatch.Groups[g.ToString()].Captures[capID].Value;
                 } else if (g is int || Int32.TryParse(g.ToString(), out gn)) {
                     return varMatch.Groups[gn].Captures[capID].Value;
                 } else {
                     return varMatch.Groups[0].Captures[capID].Value;
                 }
             case regexAct.Replace:
                 return regex.Replace(target, (string)replStr, replCnt, replStart);
             case regexAct.Matches:
                 var ms = regex.Matches(target);
                 o = ms;
                 return "0";
             default:
                 return "err:-1";
         }
     } catch{
         return "err:-2";
     }
 }
예제 #2
0
파일: REGEX.cs 프로젝트: ingted/CLRUDF
        public static string regexFun(string target, string expr, object g, regexAct ra, string replStr, int replCnt, int replStart, ref MatchCollection o, int capID)
        {
            int gn = g is int?Int32.Parse(g.ToString()) : 0;

            if (capID < 0)
            {
                capID = 0;
            }
            Regex regex = new Regex(expr, RegexOptions.Multiline | RegexOptions.IgnoreCase);

            try {
                switch (ra)
                {
                case regexAct.Match:
                    var varMatch = regex.Match(target);
                    if (!varMatch.Success)
                    {
                        return(null);
                    }
                    else if (g is String && Array.Exists(regex.GetGroupNames(), gpnm => (gpnm == g.ToString())))
                    {
                        return(varMatch.Groups[g.ToString()].Captures[capID].Value);
                    }
                    else if (g is int || Int32.TryParse(g.ToString(), out gn))
                    {
                        return(varMatch.Groups[gn].Captures[capID].Value);
                    }
                    else
                    {
                        return(varMatch.Groups[0].Captures[capID].Value);
                    }

                case regexAct.Replace:
                    return(regex.Replace(target, (string)replStr, replCnt, replStart));

                case regexAct.Matches:
                    var ms = regex.Matches(target);
                    o = ms;
                    return("0");

                default:
                    return("err:-1");
                }
            } catch {
                return("err:-2");
            }
        }
예제 #3
0
파일: REGEX.cs 프로젝트: ingted/CLRUDF
 public static string regexFun(string target, string expr, object g, regexAct ra, string replStr, int replCnt, int replStart, int capID) {
     var o = Regex.Matches("", "");
     return regexFun(target, expr, g, ra, replStr, replCnt, replStart, ref o, capID);
 }
예제 #4
0
파일: REGEX.cs 프로젝트: ingted/CLRUDF
        public static string regexFun(string target, string expr, object g, regexAct ra, string replStr, int replCnt, int replStart, int capID)
        {
            var o = Regex.Matches("", "");

            return(regexFun(target, expr, g, ra, replStr, replCnt, replStart, ref o, capID));
        }
예제 #5
0
파일: REGEX.cs 프로젝트: ingted/CLRUDF
        public static string regexFun(string target, string expr, object g, int rai, string replStr, int replCnt, int replStart, int capID)
        {
            regexAct ra = (regexAct)rai;

            return(regexFun(target, expr, g, ra, replStr, replCnt, replStart, capID));
        }