This task and my code not work as i expect : not same result * and + flag in regex
The lessons explain the differrence between * and + that either one or more times find pattern the other zero or more times.
But i dont get anything with : *
let exampleString = "iiiiiiiiiCCCCiiiii";
let exampleRegex1 = /C+/;
let exampleRegex2 = /C*/;
let result1 = exampleString.match(exampleRegex1);
let result2 = exampleString.match(exampleRegex2);
console.log(`result1: ${result1}`);
console.log(`result2: ${result2}`);
and the result:
result1: CCCC
result2:
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
so the things like β+β or β*β are called tokens. The things like βgβ, βiβ that follows a regex are known as flags.
without a βgβ flag, your regex returns the first match found and does not continue any further in the input string.
since your exampleRegex2 matches βthe character βcβ 0 or more timesβ, it goes to the very beginning of the word, says, βhey this non-character before the first character βiβ looks like 0 βCββ, and just returns you an empty string.
In other words it matches the empty string before the first char, since technically an empty string is 0 βCβ.