using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?:\[[A-Z]*-\d* \/fixed\] )?(?<type>\w*)(?:\((?<scope>[\w$.\-*\/ ]*)\))?: (?<subject>(?:.(?!(?i)\/fixed))*)$";
string substitution = @"$type $scope $subject";
string input = @"# without scope
feat: add REST endpoint /my-app/api/versions
fix: change git commit username
style: set indentation to 4 spaces
docs: explain new configuration preset
# with scope
feat(backend): add REST endpoint /my-app/api/versions
fix(default): change git commit username
style(npm): set indentation to 4 spaces
docs(terraform): explain new configuration preset
# smartcommit without scope
[CORE-1234 /fixed] feat: add REST endpoint /my-app/api/versions
[HDEFECT-1234 /fixed] fix: change git commit username
[HDEFECT-1234 /fixed] style: set indentation to 4 spaces
[HDEFECT-1234 /fixed] docs: explain new configuration preset
# smartcommit with scope
[CORE-1234 /fixed] feat(backend): add REST endpoint /my-app/api/versions
[HDEFECT-1234 /fixed] fix(default): change git commit username
[HDEFECT-1234 /fixed] style(npm): set indentation to 4 spaces
[HDEFECT-1234 /fixed] docs(terraform): explain new configuration preset
# not match - wrong smart commit
[core-1234 /fixed] feat(backend): add REST endpoint /my-app/api/versions
[hdefect-1234 /fixed] fix(default): change git commit username
[hdefect-1234 /fixed] style(npm): set indentation to 4 spaces
[hdefect-1234 /fixed] docs(terraform): explain new configuration preset
# not matched - use /fixed in title
[CORE-1234 /fixed] feat(backend): add REST endpoint /my-app/api/versions /fixed
[HDEFECT-1234 /fixed] fix(default): change git commit /fixed username
[HDEFECT-1234 /fixed] style(npm): set /FIXED indentation to 4 spaces
[HDEFECT-1234 /fixed] docs(terraform): /fixed explain new configuration preset
";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
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