diff --git a/src/GitVersion.Core/Core/RegexPatterns.cs b/src/GitVersion.Core/Core/RegexPatterns.cs index 821163cfcf..3b57dc5c4f 100644 --- a/src/GitVersion.Core/Core/RegexPatterns.cs +++ b/src/GitVersion.Core/Core/RegexPatterns.cs @@ -6,36 +6,36 @@ internal static class RegexPatterns { internal static class Common { - public static readonly Regex SwitchArgumentRegex = new(@"/\w+:", RegexOptions.Compiled); - public static readonly Regex ObscurePasswordRegex = new("(https?://)(.+)(:.+@)", RegexOptions.Compiled); + public static Regex SwitchArgumentRegex { get; } = new(@"/\w+:", RegexOptions.Compiled); + public static Regex ObscurePasswordRegex { get; } = new("(https?://)(.+)(:.+@)", RegexOptions.Compiled); // This regex matches an expression to replace. // - env:ENV name OR a member name // - optional fallback value after " ?? " // - the fallback value should be a quoted string, but simple unquoted text is allowed for back compat - public static readonly Regex ExpandTokensRegex = new("""{((env:(?\w+))|(?\w+))(\s+(\?\?)??\s+((?\w+)|"(?.*)"))??}""", RegexOptions.Compiled); + public static Regex ExpandTokensRegex { get; } = new("""{((env:(?\w+))|(?\w+))(\s+(\?\?)??\s+((?\w+)|"(?.*)"))??}""", RegexOptions.Compiled); } internal static class MergeMessage { - public static readonly Regex DefaultMergeMessageRegex = new(@"^Merge (branch|tag) '(?[^']*)'(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static readonly Regex SmartGitMergeMessageRegex = new(@"^Finish (?[^\s]*)(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static readonly Regex BitBucketPullMergeMessageRegex = new(@"^Merge pull request #(?\d+) (from|in) (?.*) from (?[^\s]*) to (?[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static readonly Regex BitBucketPullv7MergeMessageRegex = new(@"^Pull request #(?\d+).*\r?\n\r?\nMerge in (?.*) from (?[^\s]*) to (?[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static readonly Regex BitBucketCloudPullMergeMessageRegex = new(@"^Merged in (?[^\s]*) \(pull request #(?\d+)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static readonly Regex GitHubPullMergeMessageRegex = new(@"^Merge pull request #(?\d+) (from|in) (?:[^\s\/]+\/)?(?[^\s]*)(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static readonly Regex RemoteTrackingMergeMessageRegex = new(@"^Merge remote-tracking branch '(?[^\s]*)'(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static readonly Regex AzureDevOpsPullMergeMessageRegex = new(@"^Merge pull request (?\d+) from (?[^\s]*) into (?[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex DefaultMergeMessageRegex { get; } = new(@"^Merge (branch|tag) '(?[^']*)'(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex SmartGitMergeMessageRegex { get; } = new(@"^Finish (?[^\s]*)(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex BitBucketPullMergeMessageRegex { get; } = new(@"^Merge pull request #(?\d+) (from|in) (?.*) from (?[^\s]*) to (?[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex BitBucketPullv7MergeMessageRegex { get; } = new(@"^Pull request #(?\d+).*\r?\n\r?\nMerge in (?.*) from (?[^\s]*) to (?[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex BitBucketCloudPullMergeMessageRegex { get; } = new(@"^Merged in (?[^\s]*) \(pull request #(?\d+)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex GitHubPullMergeMessageRegex { get; } = new(@"^Merge pull request #(?\d+) (from|in) (?:[^\s\/]+\/)?(?[^\s]*)(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex RemoteTrackingMergeMessageRegex { get; } = new(@"^Merge remote-tracking branch '(?[^\s]*)'(?: into (?[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public static Regex AzureDevOpsPullMergeMessageRegex { get; } = new(@"^Merge pull request (?\d+) from (?[^\s]*) into (?[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); } internal static class Output { - public static readonly Regex AssemblyVersionRegex = new(@"AssemblyVersion(Attribute)?\s*\(.*\)\s*"); - public static readonly Regex AssemblyInfoVersionRegex = new(@"AssemblyInformationalVersion(Attribute)?\s*\(.*\)\s*"); - public static readonly Regex AssemblyFileVersionRegex = new(@"AssemblyFileVersion(Attribute)?\s*\(.*\)\s*"); - public static readonly Regex CsharpAssemblyAttributeRegex = new(@"(\s*\[\s*assembly:\s*(?:.*)\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline); - public static readonly Regex FsharpAssemblyAttributeRegex = new(@"(\s*\[\s*\\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline); - public static readonly Regex VisualBasicAssemblyAttributeRegex = new(@"(\s*\\s*$(\r?\n)?)", RegexOptions.Multiline); + public static Regex AssemblyVersionRegex { get; } = new(@"AssemblyVersion(Attribute)?\s*\(.*\)\s*"); + public static Regex AssemblyInfoVersionRegex { get; } = new(@"AssemblyInformationalVersion(Attribute)?\s*\(.*\)\s*"); + public static Regex AssemblyFileVersionRegex { get; } = new(@"AssemblyFileVersion(Attribute)?\s*\(.*\)\s*"); + public static Regex CsharpAssemblyAttributeRegex { get; } = new(@"(\s*\[\s*assembly:\s*(?:.*)\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline); + public static Regex FsharpAssemblyAttributeRegex { get; } = new(@"(\s*\[\s*\\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline); + public static Regex VisualBasicAssemblyAttributeRegex { get; } = new(@"(\s*\\s*$(\r?\n)?)", RegexOptions.Multiline); } internal static class VersionCalculation @@ -52,31 +52,31 @@ internal static class VersionCalculation //language=regexp public const string DefaultNoBumpPattern = @"\+semver:\s?(none|skip)"; - public static readonly Regex DefaultMajorPatternRegex = new(DefaultMajorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static readonly Regex DefaultMinorPatternRegex = new(DefaultMinorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static readonly Regex DefaultPatchPatternRegex = new(DefaultPatchPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static readonly Regex DefaultNoBumpPatternRegex = new(DefaultNoBumpPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); + public static Regex DefaultMajorPatternRegex { get; } = new(DefaultMajorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); + public static Regex DefaultMinorPatternRegex { get; } = new(DefaultMinorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); + public static Regex DefaultPatchPatternRegex { get; } = new(DefaultPatchPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); + public static Regex DefaultNoBumpPatternRegex { get; } = new(DefaultNoBumpPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); } internal static class SemanticVersion { // uses the git-semver spec https://github.com/semver/semver/blob/master/semver.md - public static readonly Regex ParseStrictRegex = new( + public static Regex ParseStrictRegex { get; } = new( @"^(?0|[1-9]\d*)\.(?0|[1-9]\d*)\.(?0|[1-9]\d*)(?:-(?(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$", RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static readonly Regex ParseLooseRegex = new( + public static Regex ParseLooseRegex { get; } = new( @"^(?(?\d+)(\.(?\d+))?(\.(?\d+))?)(\.(?\d+))?(-(?[^\+]*))?(\+(?.*))?$", RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static readonly Regex ParseBuildMetaDataRegex = new( + public static Regex ParseBuildMetaDataRegex { get; } = new( @"(?\d+)?(\.?Branch(Name)?\.(?[^\.]+))?(\.?Sha?\.(?[^\.]+))?(?.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static readonly Regex FormatBuildMetaDataRegex = new("[^0-9A-Za-z-.]", + public static Regex FormatBuildMetaDataRegex { get; } = new("[^0-9A-Za-z-.]", RegexOptions.Compiled | RegexOptions.IgnoreCase); - public static readonly Regex ParsePreReleaseTagRegex = new( + public static Regex ParsePreReleaseTagRegex { get; } = new( @"(?.*?)\.?(?\d+)?$", RegexOptions.Compiled | RegexOptions.IgnoreCase); }