Can anyone explain how this is able to solve the challenge
// example crowd gathering
let crowd = 'P1P5P4CCCP2P6P3';
let reCriminals =** /[.|C]+/**; // Change this line
let matchedCriminals = crowd.match(reCriminals);
console.log(matchedCriminals);
You’re matching one or more of .
, |
or C
.
Remember that inside a character set (these brackets []
) you’re matching the character itself, so .
and |
aren’t doing anything special there.
You can basically do this and still pass (note that there’s no P
in there):
/[ABDEFGHIJKLMNOQRSTVXWYZC.,|]+/
Of course, something like /C+/
is more appropriate.
Thanks, I later understood what was going on. it just felt so weird that i couldn’t wrap my head around how it worked at that time