Find One or More Criminals in a Hunt
Let's Write a greedy regex that finds one or more criminals within a group of other people. A criminal is represented by the capital letter C.
Here's an example to review how to do this:
/z+/matches the letter
zwhen it appears one or more times in a row. It would find matches in all of the following strings:
"z" "zzzzzz" "ABCzzzz" "zzzzABC" "abczzzzzzzzzzzzzzzzzzzzzabc"
- But it does not find matches in the following strings since there are no letter
"" "ABC" "abcabc"
let reCriminals = /C+/;
- Now your regex should match three criminals (CCC) in the string P1P5P4CCCcP2P6P3.
- Now your regex should match five criminals (CCCCC) in the string P6P2P7P4P5CCCCCP3P1.
Top comments (0)