aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Extensions.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs
index 20620e44..077f5b17 100644
--- a/src/slskd/Common/Extensions.cs
+++ b/src/slskd/Common/Extensions.cs
@@ -23,6 +23,7 @@ namespace slskd
using System.Linq;
using System.Reflection;
using System.Text.Json;
+ using System.Text.RegularExpressions;
/// <summary>
/// Extensions.
@@ -118,6 +119,30 @@ namespace slskd
}
/// <summary>
+ /// Determines whether the string is a valid regular expression.
+ /// </summary>
+ /// <param name="pattern">The string to validate.</param>
+ /// <returns>A value indicating whether the string is a valid regular expression.</returns>
+ public static bool IsValidRegex(this string pattern)
+ {
+ if (string.IsNullOrWhiteSpace(pattern))
+ {
+ return false;
+ }
+
+ try
+ {
+ Regex.Match(string.Empty, pattern);
+ }
+ catch (ArgumentException)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /// <summary>
/// Deeply compares this object with the specified object and returns a list of properties that are different.
/// </summary>
/// <param name="left">The left side of the comparison.</param>