Ejemplo n.º 1
0
        /// <summary>
        /// Возвращает совпадения для регулярного выражения
        /// </summary>
        public static string [] GetMatches(this string str, string pattern, RegExOptions options)
        {
            if (str.IsMatch(pattern, options))
            {
                return(Regex.Matches(str, pattern, (RegexOptions)options).Cast <Match>().Select(m => m.Value).ToArray());
            }

            return(new string[] { });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Проверяет соответствие регулярному выражению
 /// </summary>
 public static bool IsMatch(this string str, string pattern, RegExOptions options)
 {
     return(Regex.IsMatch(str, pattern, (RegexOptions)options));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Замена в строке через регулярное выражение
 /// </summary>
 /// <param name="regExpr">Регулярное выражение</param>
 /// <param name="str">Строка</param>
 /// <param name="replStr">Строка-замена</param>
 /// <param name="options">Опции регулярного выражения</param>
 /// <returns></returns>
 public static string ReplaceRegex(this string str, string regExpr, string replStr, RegExOptions options)
 {
     return(str == null
         ? string.Empty
         : Regex.Replace(str, regExpr, replStr, (RegexOptions)options));
 }