Find One or More Criminals in a Hunt--

Find One or More Criminals in a Hunt--
0

#1

Tell us what’s happening:
I tried all the options but I can’t get the challenge right

Your code so far


// example crowd gathering
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';

let reCriminals = /[^.]c*/i; // Change this line

let matchedCriminals = crowd.match(reCriminals);
console.log(matchedCriminals);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/find-one-or-more-criminals-in-a-hunt


#2

First, [^.] means ‘match any character other than a character’, which doesn’t make sense. Omit it.

Second, criminals are denoted by ‘C’ not ‘c’. So you can use ‘C’ and remove the ‘i’ tag which ignores the letter case.

Third, you are supposed to match one or more criminals ©, so the ‘+’ character is required (not ‘*’).

Last, since the criminals may not all be next to each other, you need to search for all groups. This is done by adding a ‘g’ (global) tag.

For more on regexp check out https://medium.freecodecamp.org/regular-expressions-demystified-regex-isnt-as-hard-as-it-looks-617b55cf787


#3

Thanks alot @joops75


#4

Actually, [^.] means ‘match any character other than a dot’. Outside of square brackets, ‘.’ means ‘any character’. Inside them, it means itself, ‘.’ (dot).