コード例 #1
0
ファイル: SQLRegEx.cs プロジェクト: PavelPawlowski/PPSqlClr
    public static SqlChars RegExReplace(SqlString sourceString, SqlString pattern, SqlString replacement, int matchId, SqlString options)
    {
        RegexOptions regOptions = RegexOptions.None;

        RegexOptionsEnum.TyPrase(options.Value, out regOptions);

        regOptions |= RegexOptions.Compiled;

        Match m = null;
        Regex r = new Regex(pattern.Value, regOptions);

        if (matchId == 0)
        {
            return(new SqlChars(r.Replace(sourceString.Value, replacement.Value)));
        }
        if (matchId == 1)
        {
            m = r.Match(sourceString.Value);
        }
        else if (matchId > 1)
        {
            MatchCollection mc = r.Matches(sourceString.Value);
            m = mc != null && mc.Count > matchId - 1 ? mc[matchId - 1] : null;
        }

        return(m != null ? new SqlChars(m.Result(replacement.Value)) : SqlChars.Null);
    }
コード例 #2
0
ファイル: SQLRegEx.cs プロジェクト: PavelPawlowski/PPSqlClr
    public static IEnumerable RegExMatches(SqlString sourceString, SqlString pattern, SqlString options)
    {
        RegexOptions regOptions = RegexOptions.None;

        RegexOptionsEnum.TyPrase(options.Value, out regOptions);

        regOptions |= RegexOptions.Compiled;

        Regex r       = new Regex(pattern.Value, regOptions);
        int   rowId   = 0;
        int   matchId = 0;

        string[] grpNames = r.GetGroupNames();
        foreach (Match m in r.Matches(sourceString.Value))
        {
            matchId++;
            for (int i = 0; i < m.Groups.Count; i++)
            {
                string grpName = grpNames[i];
                var    grp     = m.Groups[i];

                for (int j = 0; j < grp.Captures.Count; j++)
                {
                    var cap = grp.Captures[j];
                    yield return(new RegExRow(++rowId, matchId, i, grpName, grp.Success, j, new SqlChars(cap.Value)));
                }
            }
        }
    }
コード例 #3
0
ファイル: SQLRegEx.cs プロジェクト: PavelPawlowski/PPSqlClr
    public static SqlChars RegExMatchName(SqlString sourceString, SqlString pattern, int matchId, SqlString groupname, SqlString options)
    {
        RegexOptions regOptions = RegexOptions.None;

        RegexOptionsEnum.TyPrase(options.Value, out regOptions);

        regOptions |= RegexOptions.Compiled;

        Match m = null;
        Regex r = new Regex(pattern.Value, regOptions);

        if (matchId == 1)
        {
            m = r.Match(sourceString.Value);
        }
        else if (matchId > 1)
        {
            MatchCollection mc = r.Matches(sourceString.Value);
            m = mc != null && mc.Count > matchId - 1 ? mc[matchId - 1] : null;
        }

        if (groupname.IsNull || string.IsNullOrEmpty(groupname.Value))
        {
            return(new SqlChars(m.Value));
        }
        else
        {
            return(m != null ? new SqlChars(m.Groups[groupname.Value].Value) : SqlChars.Null);
        }
    }
コード例 #4
0
ファイル: SQLRegEx.cs プロジェクト: PavelPawlowski/PPSqlClr
    public static SqlBoolean RegExIsMatch(SqlString sourceString, SqlString pattern, SqlString options)
    {
        RegexOptions regOptions = RegexOptions.None;

        RegexOptionsEnum.TyPrase(options.Value, out regOptions);

        regOptions |= RegexOptions.Compiled;

        Regex r = new Regex(pattern.Value, regOptions);

        return(new SqlBoolean(r.IsMatch(sourceString.Value)));
    }
コード例 #5
0
ファイル: SQLRegEx.cs プロジェクト: PavelPawlowski/PPSqlClr
    public static IEnumerable RegExMatchesReplace(SqlString sourceString, SqlString pattern, SqlString replacement, SqlString options)
    {
        RegexOptions regOptions = RegexOptions.None;

        RegexOptionsEnum.TyPrase(options.Value, out regOptions);

        regOptions |= RegexOptions.Compiled;

        Regex r       = new Regex(pattern.Value, regOptions);
        int   matchId = 0;

        foreach (Match m in r.Matches(sourceString.Value))
        {
            yield return(new RegExRowReplace(++matchId, new SqlChars(m.Value), new SqlChars(m.Result(replacement.Value))));
        }
    }