Skip to content

Commit ec5306b

Browse files
authored
Merge pull request #4209 from arturcic/main
Move regex patterns to a common file
2 parents 719899e + a959326 commit ec5306b

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/GitVersion.Core/Core/RegexPatterns.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ internal static class RegexPatterns
66
{
77
internal static class Common
88
{
9-
public static readonly Regex SwitchArgumentRegex = new(@"/\w+:", RegexOptions.Compiled);
10-
public static readonly Regex ObscurePasswordRegex = new("(https?://)(.+)(:.+@)", RegexOptions.Compiled);
9+
public static Regex SwitchArgumentRegex { get; } = new(@"/\w+:", RegexOptions.Compiled);
10+
public static Regex ObscurePasswordRegex { get; } = new("(https?://)(.+)(:.+@)", RegexOptions.Compiled);
1111

1212
// This regex matches an expression to replace.
1313
// - env:ENV name OR a member name
1414
// - optional fallback value after " ?? "
1515
// - the fallback value should be a quoted string, but simple unquoted text is allowed for back compat
16-
public static readonly Regex ExpandTokensRegex = new("""{((env:(?<envvar>\w+))|(?<member>\w+))(\s+(\?\?)??\s+((?<fallback>\w+)|"(?<fallback>.*)"))??}""", RegexOptions.Compiled);
16+
public static Regex ExpandTokensRegex { get; } = new("""{((env:(?<envvar>\w+))|(?<member>\w+))(\s+(\?\?)??\s+((?<fallback>\w+)|"(?<fallback>.*)"))??}""", RegexOptions.Compiled);
1717
}
1818

1919
internal static class MergeMessage
2020
{
21-
public static readonly Regex DefaultMergeMessageRegex = new(@"^Merge (branch|tag) '(?<SourceBranch>[^']*)'(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
22-
public static readonly Regex SmartGitMergeMessageRegex = new(@"^Finish (?<SourceBranch>[^\s]*)(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
23-
public static readonly Regex BitBucketPullMergeMessageRegex = new(@"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?<Source>.*) from (?<SourceBranch>[^\s]*) to (?<TargetBranch>[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
24-
public static readonly Regex BitBucketPullv7MergeMessageRegex = new(@"^Pull request #(?<PullRequestNumber>\d+).*\r?\n\r?\nMerge in (?<Source>.*) from (?<SourceBranch>[^\s]*) to (?<TargetBranch>[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
25-
public static readonly Regex BitBucketCloudPullMergeMessageRegex = new(@"^Merged in (?<SourceBranch>[^\s]*) \(pull request #(?<PullRequestNumber>\d+)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
26-
public static readonly Regex GitHubPullMergeMessageRegex = new(@"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?:[^\s\/]+\/)?(?<SourceBranch>[^\s]*)(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
27-
public static readonly Regex RemoteTrackingMergeMessageRegex = new(@"^Merge remote-tracking branch '(?<SourceBranch>[^\s]*)'(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
28-
public static readonly Regex AzureDevOpsPullMergeMessageRegex = new(@"^Merge pull request (?<PullRequestNumber>\d+) from (?<SourceBranch>[^\s]*) into (?<TargetBranch>[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
21+
public static Regex DefaultMergeMessageRegex { get; } = new(@"^Merge (branch|tag) '(?<SourceBranch>[^']*)'(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
22+
public static Regex SmartGitMergeMessageRegex { get; } = new(@"^Finish (?<SourceBranch>[^\s]*)(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
23+
public static Regex BitBucketPullMergeMessageRegex { get; } = new(@"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?<Source>.*) from (?<SourceBranch>[^\s]*) to (?<TargetBranch>[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
24+
public static Regex BitBucketPullv7MergeMessageRegex { get; } = new(@"^Pull request #(?<PullRequestNumber>\d+).*\r?\n\r?\nMerge in (?<Source>.*) from (?<SourceBranch>[^\s]*) to (?<TargetBranch>[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
25+
public static Regex BitBucketCloudPullMergeMessageRegex { get; } = new(@"^Merged in (?<SourceBranch>[^\s]*) \(pull request #(?<PullRequestNumber>\d+)\)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
26+
public static Regex GitHubPullMergeMessageRegex { get; } = new(@"^Merge pull request #(?<PullRequestNumber>\d+) (from|in) (?:[^\s\/]+\/)?(?<SourceBranch>[^\s]*)(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
27+
public static Regex RemoteTrackingMergeMessageRegex { get; } = new(@"^Merge remote-tracking branch '(?<SourceBranch>[^\s]*)'(?: into (?<TargetBranch>[^\s]*))*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
28+
public static Regex AzureDevOpsPullMergeMessageRegex { get; } = new(@"^Merge pull request (?<PullRequestNumber>\d+) from (?<SourceBranch>[^\s]*) into (?<TargetBranch>[^\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
2929
}
3030

3131
internal static class Output
3232
{
33-
public static readonly Regex AssemblyVersionRegex = new(@"AssemblyVersion(Attribute)?\s*\(.*\)\s*");
34-
public static readonly Regex AssemblyInfoVersionRegex = new(@"AssemblyInformationalVersion(Attribute)?\s*\(.*\)\s*");
35-
public static readonly Regex AssemblyFileVersionRegex = new(@"AssemblyFileVersion(Attribute)?\s*\(.*\)\s*");
36-
public static readonly Regex CsharpAssemblyAttributeRegex = new(@"(\s*\[\s*assembly:\s*(?:.*)\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline);
37-
public static readonly Regex FsharpAssemblyAttributeRegex = new(@"(\s*\[\s*\<assembly:\s*(?:.*)\>\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline);
38-
public static readonly Regex VisualBasicAssemblyAttributeRegex = new(@"(\s*\<Assembly:\s*(?:.*)\>\s*$(\r?\n)?)", RegexOptions.Multiline);
33+
public static Regex AssemblyVersionRegex { get; } = new(@"AssemblyVersion(Attribute)?\s*\(.*\)\s*");
34+
public static Regex AssemblyInfoVersionRegex { get; } = new(@"AssemblyInformationalVersion(Attribute)?\s*\(.*\)\s*");
35+
public static Regex AssemblyFileVersionRegex { get; } = new(@"AssemblyFileVersion(Attribute)?\s*\(.*\)\s*");
36+
public static Regex CsharpAssemblyAttributeRegex { get; } = new(@"(\s*\[\s*assembly:\s*(?:.*)\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline);
37+
public static Regex FsharpAssemblyAttributeRegex { get; } = new(@"(\s*\[\s*\<assembly:\s*(?:.*)\>\s*\]\s*$(\r?\n)?)", RegexOptions.Multiline);
38+
public static Regex VisualBasicAssemblyAttributeRegex { get; } = new(@"(\s*\<Assembly:\s*(?:.*)\>\s*$(\r?\n)?)", RegexOptions.Multiline);
3939
}
4040

4141
internal static class VersionCalculation
@@ -52,31 +52,31 @@ internal static class VersionCalculation
5252
//language=regexp
5353
public const string DefaultNoBumpPattern = @"\+semver:\s?(none|skip)";
5454

55-
public static readonly Regex DefaultMajorPatternRegex = new(DefaultMajorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
56-
public static readonly Regex DefaultMinorPatternRegex = new(DefaultMinorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
57-
public static readonly Regex DefaultPatchPatternRegex = new(DefaultPatchPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
58-
public static readonly Regex DefaultNoBumpPatternRegex = new(DefaultNoBumpPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
55+
public static Regex DefaultMajorPatternRegex { get; } = new(DefaultMajorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
56+
public static Regex DefaultMinorPatternRegex { get; } = new(DefaultMinorPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
57+
public static Regex DefaultPatchPatternRegex { get; } = new(DefaultPatchPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
58+
public static Regex DefaultNoBumpPatternRegex { get; } = new(DefaultNoBumpPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
5959
}
6060

6161
internal static class SemanticVersion
6262
{
6363
// uses the git-semver spec https://github.com/semver/semver/blob/master/semver.md
64-
public static readonly Regex ParseStrictRegex = new(
64+
public static Regex ParseStrictRegex { get; } = new(
6565
@"^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$",
6666
RegexOptions.Compiled | RegexOptions.IgnoreCase);
6767

68-
public static readonly Regex ParseLooseRegex = new(
68+
public static Regex ParseLooseRegex { get; } = new(
6969
@"^(?<SemVer>(?<Major>\d+)(\.(?<Minor>\d+))?(\.(?<Patch>\d+))?)(\.(?<FourthPart>\d+))?(-(?<Tag>[^\+]*))?(\+(?<BuildMetaData>.*))?$",
7070
RegexOptions.Compiled | RegexOptions.IgnoreCase);
7171

72-
public static readonly Regex ParseBuildMetaDataRegex = new(
72+
public static Regex ParseBuildMetaDataRegex { get; } = new(
7373
@"(?<BuildNumber>\d+)?(\.?Branch(Name)?\.(?<BranchName>[^\.]+))?(\.?Sha?\.(?<Sha>[^\.]+))?(?<Other>.*)",
7474
RegexOptions.Compiled | RegexOptions.IgnoreCase);
7575

76-
public static readonly Regex FormatBuildMetaDataRegex = new("[^0-9A-Za-z-.]",
76+
public static Regex FormatBuildMetaDataRegex { get; } = new("[^0-9A-Za-z-.]",
7777
RegexOptions.Compiled | RegexOptions.IgnoreCase);
7878

79-
public static readonly Regex ParsePreReleaseTagRegex = new(
79+
public static Regex ParsePreReleaseTagRegex { get; } = new(
8080
@"(?<name>.*?)\.?(?<number>\d+)?$",
8181
RegexOptions.Compiled | RegexOptions.IgnoreCase);
8282
}

0 commit comments

Comments
 (0)