const regex = new RegExp('\\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', 'm')
const str = `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`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions