const regex = new RegExp('(?P<assign_op>(\\:|\\!|\\?)?=)|(?P<token_subst>$|%(\\<\\@))|(?P<token_ident>[\\w\\d\\.\\,]+)|(?P<target_name_match>%\\.?)|(?P<token_rule_sep>[:])|(?P<incr_op>\\n)|(?P<line_end>\\n)|(?P<comment_op>#[.*]+$)|(?P<adjust_parser>[\\$%\\s\\t\\:])', 'gm')
const str = `CC := nasm
BOOT_REQ := text.o
FREELDR_SRCS := freeldr.c
IMG_NAME := boot.img
TEXT_SECTION := 7c00
# UFS2, ZFS and/or RAW
FILESYSTEMS :=
CPU_FLAGS := PAE
SDK_FLAGS :=
VERSION := "1.00.00"
%.o:
\$(ASM) \${SDK_FLAGS} -f bin -o \$@ \$(patsubst %.bin,%.asm,\$@))
\${IMG_NAME}:
\$(BOOT_REQ) \$(FREELDR_SRCS:.c=.o)
`;
// 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