const regex = /^(((0|[1-9]\d*)\.)(((0|[1-9]\d*|x)\.)?x)|main|next(-major)?|beta|alpha)$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(((0|[1-9]\\d*)\\.)(((0|[1-9]\\d*|x)\\.)?x)|main|next(-major)?|beta|alpha)$', 'gm')
const str = `Inspired by Semantic Release Distributions Channels from Branches: https://semantic-release.gitbook.io/semantic-release/usage/configuration#branches
Valid Semantic Release Distribution Channels:
0.0.x
0.x.x
0.x
1.2.x
1.x.x
1.x
10.20.x
10.x.x
10.x
1.0.x
2.0.x
2.x.x
2.x
1.1.x
99999999999999999999999.999999999999999999.x
99999999999999999999999.x.x
99999999999999999999999.x
main
next
next-major
beta
alpha
Inalid Semantic Release Distribution Channels:
x
0.
0.xx
00.0.x
1.2
01.x
1.02.x
1.x.0
x.20.x
x.x.x
x.0.x
2.0.x-alpha
2.0.x+meta
x.x
01.1.x
99999999999999999999999.0999999999999999999.x
099999999999999999999999.x.x
mains
pre-next
next-minor
beta+
-alpha
gamma
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// 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