const regex = /(\()|(?:(([udfblrmesxyz])(?:([-i'])|(2))?)|(\[((?:(?:[ud][fb]|[fb][ud])(?:[lr]?)|(?:[fb][lr]|[lr][fb])(?:[ud]?)|(?:[ud][lr]|[lr][ud])(?:[fb]?))|(?:o[24][udfb]|o6[lr]|c[cw][23]|pt[jn]|par|prn))]))|(\)([1-9min'])?)/ig;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\()|(?:(([udfblrmesxyz])(?:([-i\'])|(2))?)|(\\[((?:(?:[ud][fb]|[fb][ud])(?:[lr]?)|(?:[fb][lr]|[lr][fb])(?:[ud]?)|(?:[ud][lr]|[lr][ud])(?:[fb]?))|(?:o[24][udfb]|o6[lr]|c[cw][23]|pt[jn]|par|prn))]))|(\\)([1-9min\'])?)', 'ig')
const str = `face rotations: fblrudf'b'l'r'u'd'fibiliriuidi
axis rotations: xyzx'y'z'xiyizi
pieces: [uf][ub][df][db][fu][bu][fd][bd][fl][fr][bl][br][lf][rf][lb][rb][ur][ul][dr][dl][ru][lu][rd][ld][urf][ufr]...
patterns: [o2u][o2f]...[o4d][o4b]...[o6l][o6r][cc2][cc3][cw2][cw3][par][ptn][ptj][prn]
groups: (rf) (rf)'(rf)n (rf)i (rf)m (rf)3
mixed (and test):
[f'r-abix2]
[r2u]
(r(fr)i[FR])m f`;
// 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