using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\A(?:(?P<type>[^\(!:]+)(?:\((?P<scope>[^\)]+)\))?(?P<breaking>!)?: (?P<description>.+))(?:(?!(?:\n{2}^(?:BREAKING[ -]CHANGE|[a-zA-Z0-9_\-]+)(?:: | #\b)[^\n:]+(\n*\b)?)+)\n{2}(?P<body>(?:(?!\n{2}(?:^(?:BREAKING[ -]CHANGE|[a-zA-Z0-9_\-]+)(?:: | #\b)[^\n:]+(\n*\b)?)+).|\n+?)+?))?(?:\n{2}(?P<footers>(?:^(?:BREAKING[ -]CHANGE|[a-zA-Z0-9_\-]+)(?:: | #\b)[^\n:]+(\n*\b)?)+))?(?:\n*)\Z";
string input = @"feat(foo): add a nice RegEx to check and parse a commit message that folows https://www.conventionalcommits.org/en/v1.0.0
Hello,
This is an
multiline example and very nice
This may also include colons as long as they are not after a word boundary followed after two line brakes
Example: foo
Other example: xyz
Refs: #42
BREAKING-CHANGE: Brakes wood
something #mentions a commit";
RegexOptions options = RegexOptions.Multiline;
Match m = Regex.Match(input, pattern, options);
Console.WriteLine("'{0}' found at index {1}", m.Value, m.Index);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx