const regex = new RegExp('((@[\\w\\d][\\w\\d_]+)\\s+)?(\\.[\\w\\d][\\w\\d_]+\\s+)', 'gm')
const str = `@array .byte 3, 4, 23
va1 .byte 'A', -3, 0xAB // Three bytes
@str1 .byte "Enter an integer: " // Null-terminated string
@var2 .hword 0xABCD:10 // 0xABCD is replicated 10 times
@var3 .word -18, 5.7E-3 // 4-byte integer, single float
@var4 .dword 21, 21.0 // 8-byte integer, double float
//Assembly Language Syntax:
J @label // Jump @label
JAL @label // R31 = (PC+4); Jump @label
The JAL instruction saves the return address `;
// 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