I'm currently reading "Learning JavaScript" by Ethan Brown (2016). I'm going through the examples in the Backreferences section and they keep coming up as 'null'. There are two examples.
Example 1: Match names that follow the pattern XYYX.
const promo = "Opening for XAAX is the dynamic GOOG! At the box office now!";
const bands = promo.match(/(?:[A-Z])(?:[A-Z])\2\1/g);
console.log('bands: '+ bands);//output was null
If I understand the text correctly, the result should be...
bands: XAAX, GOOG
Example 2: Matching single and/or double quotation marks.
//we use backticks here because we're using single and
//double quotation marks:
const html = `<img alt='A "simple" example,'>` +
`<img alt="Don't abuse it!">`;
const matches = html.match(/<img alt=(?:['"]).*?\1/g);
console.log('matches: '+ matches);//output was null
Again, if I understand the text correctly, the result should not be 'null'. The text doesn't say exactly what the result should be.
I'm at a loss trying to figure out why when I run this in Node.js it keeps giving me 'null' for these two examples. Anyone have any insight?