diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs index 23f3a4f4c8..101fa80829 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/Transmission.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text.RegularExpressions; using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; @@ -78,7 +77,7 @@ protected override ValidationFailure ValidateVersion() _logger.Debug("Transmission version information: {0}", versionString); - var versionResult = Regex.Match(versionString, @"(? { + protected static readonly Regex VersionRegex = new Regex(@"(?= new Version(major, minor); diff --git a/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs b/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs index 2647902480..7f10e55fc0 100644 --- a/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs +++ b/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs @@ -51,6 +51,7 @@ public XbmcMetadata(IDetectXbmcNfo detectNfo, private static readonly Regex MovieImagesRegex = new Regex(@"^(?poster|banner|fanart|clearart|discart|keyart|landscape|logo|backdrop|clearlogo)\.(?:png|jpe?g)", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex MovieFileImageRegex = new Regex(@"(?-thumb|-poster|-banner|-fanart|-clearart|-discart|-keyart|-landscape|-logo|-backdrop|-clearlogo)\.(?:png|jpe?g)", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly Regex WatchedRegex = new Regex("true", RegexOptions.Compiled, TimeSpan.FromSeconds(1)); public override string Name => "Kodi (XBMC) / Emby"; @@ -489,7 +490,7 @@ private bool GetExistingWatchedStatus(Movie movie, string movieFilePath) var fileContent = _diskProvider.ReadAllText(fullPath); - return Regex.IsMatch(fileContent, "true"); + return WatchedRegex.IsMatch(fileContent); } } } diff --git a/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs b/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs index aeb4d78038..cabc4e802a 100644 --- a/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs +++ b/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -12,6 +13,7 @@ public abstract class SearchCriteriaBase private static readonly Regex SpecialCharacter = new Regex(@"['.\u0060\u00B4\u2018\u2019]", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex NonWord = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex BeginningThe = new Regex(@"^the\s", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex RepeatingPlusRegex = new Regex(@"\+{2,}", RegexOptions.Compiled, TimeSpan.FromSeconds(1)); public Movie Movie { get; set; } public List SceneTitles { get; set; } @@ -32,7 +34,7 @@ public static string GetCleanSceneTitle(string title) cleanTitle = NonWord.Replace(cleanTitle, "+"); // remove any repeating +s - cleanTitle = Regex.Replace(cleanTitle, @"\+{2,}", "+"); + cleanTitle = RepeatingPlusRegex.Replace(cleanTitle, "+"); cleanTitle = cleanTitle.RemoveAccent(); return cleanTitle.Trim('+', ' '); } diff --git a/src/NzbDrone.Core/MetadataSource/SearchMovieComparer.cs b/src/NzbDrone.Core/MetadataSource/SearchMovieComparer.cs index d354464524..2267615b5f 100644 --- a/src/NzbDrone.Core/MetadataSource/SearchMovieComparer.cs +++ b/src/NzbDrone.Core/MetadataSource/SearchMovieComparer.cs @@ -11,6 +11,7 @@ public class SearchMovieComparer : IComparer private static readonly Regex RegexCleanPunctuation = new Regex("[-._:]", RegexOptions.Compiled); private static readonly Regex RegexCleanCountryYearPostfix = new Regex(@"(?<=.+)( \([A-Z]{2}\)| \(\d{4}\)| \([A-Z]{2}\) \(\d{4}\))$", RegexOptions.Compiled); private static readonly Regex ArticleRegex = new Regex(@"^(a|an|the)\s", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex QueryYearRegex = new Regex(@"^(?.+)\s+(?:\((?\d{4})\)|(?\d{4}))$", RegexOptions.Compiled, TimeSpan.FromSeconds(1)); public string SearchQuery { get; private set; } @@ -21,7 +22,7 @@ public SearchMovieComparer(string searchQuery) { SearchQuery = searchQuery; - var match = Regex.Match(SearchQuery, @"^(?.+)\s+(?:\((?\d{4})\)|(?\d{4}))$"); + var match = QueryYearRegex.Match(SearchQuery); if (match.Success) { _searchQueryWithoutYear = match.Groups["query"].Value.ToLowerInvariant();