Обнновлено до .net10
This commit is contained in:
@@ -1,50 +1,49 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace YandexMusic.API.Extensions
|
||||
namespace YandexMusic.API.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static class StringExtensions
|
||||
public static string ReplaceRegex(this string str, string regExpr, string replStr, RegexOptions options = RegexOptions.IgnoreCase)
|
||||
{
|
||||
public static string ReplaceRegex(this string str, string regExpr, string replStr, RegexOptions options = RegexOptions.IgnoreCase)
|
||||
{
|
||||
return str == null
|
||||
? string.Empty
|
||||
: Regex.Replace(str, regExpr, replStr);
|
||||
}
|
||||
return str == null
|
||||
? string.Empty
|
||||
: Regex.Replace(str, regExpr, replStr);
|
||||
}
|
||||
|
||||
public static string SplitByCapitalLetter(this string str, string delimiter)
|
||||
{
|
||||
return string.Join(delimiter, Regex.Matches(str, @"([A-Z]+)(?=([A-Z][a-z]|$)) | [A-Z][a-z].+?(?=([A-Z]|$))", RegexOptions.IgnorePatternWhitespace)
|
||||
public static string SplitByCapitalLetter(this string str, string delimiter)
|
||||
{
|
||||
return string.Join(delimiter, Regex.Matches(str, @"([A-Z]+)(?=([A-Z][a-z]|$)) | [A-Z][a-z].+?(?=([A-Z]|$))", RegexOptions.IgnorePatternWhitespace)
|
||||
.Cast<Match>()
|
||||
.Select(m => m.ToString()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверяет соответствие регулярному выражению
|
||||
/// </summary>
|
||||
public static bool IsMatch(this string str, string pattern, RegexOptions options)
|
||||
{
|
||||
return Regex.IsMatch(str, pattern, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверяет соответствие регулярному выражению
|
||||
/// </summary>
|
||||
public static bool IsMatch(this string str, string pattern)
|
||||
{
|
||||
return IsMatch(str, pattern, RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает совпадения для регулярного выражения
|
||||
/// </summary>
|
||||
public static string[] GetMatches(this string str, string pattern, RegexOptions options = RegexOptions.IgnoreCase)
|
||||
{
|
||||
return str.IsMatch(pattern, options)
|
||||
? Regex.Matches(str, pattern, options)
|
||||
.Cast<Match>()
|
||||
.Select(m => m.ToString()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверяет соответствие регулярному выражению
|
||||
/// </summary>
|
||||
public static bool IsMatch(this string str, string pattern, RegexOptions options)
|
||||
{
|
||||
return Regex.IsMatch(str, pattern, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверяет соответствие регулярному выражению
|
||||
/// </summary>
|
||||
public static bool IsMatch(this string str, string pattern)
|
||||
{
|
||||
return IsMatch(str, pattern, RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает совпадения для регулярного выражения
|
||||
/// </summary>
|
||||
public static string[] GetMatches(this string str, string pattern, RegexOptions options = RegexOptions.IgnoreCase)
|
||||
{
|
||||
return str.IsMatch(pattern, options)
|
||||
? Regex.Matches(str, pattern, options)
|
||||
.Cast<Match>()
|
||||
.Select(m => m.Value)
|
||||
.ToArray()
|
||||
: new string[] { };
|
||||
}
|
||||
.Select(m => m.Value)
|
||||
.ToArray()
|
||||
: new string[] { };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user