const regex = /^(?::\w*:|(?:(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])))\s(?<type>\w*)(?:\((?<scope>.*)\))?!?:\s(?<subject>(?:(?!#).)*(?:(?!\s).))(?:\s\(?(?<ticket>#\d*)\)?)?$/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?::\\w*:|(?:(\\u00a9|\\u00ae|[\\u2000-\\u3300]|\\ud83c[\\ud000-\\udfff]|\\ud83d[\\ud000-\\udfff]|\\ud83e[\\ud000-\\udfff])))\\s(?<type>\\w*)(?:\\((?<scope>.*)\\))?!?:\\s(?<subject>(?:(?!#).)*(?:(?!\\s).))(?:\\s\\(?(?<ticket>#\\d*)\\)?)?$', '')
const str = `โจ feat: add signup pages from (#11)
๐งน feat: add signup pages from (#11)
๐ feat: add signup pages from (#11)
๐ feat: add signup pages from (#11)
๐ feat: add signup pages from (#11)
๐ feat: add signup pages from (#11)
๐งช feat: add signup pages from (#11)
๐ฆ feat: add signup pages from (#11)
โช๏ธ feat: add signup pages from (#11)
โป๏ธ feat: add signup pages from (#11)
๐๏ธ feat: add signup pages from (#11)
`;
// 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