Regex * and + help

Tell us what’s happening:
Hi guys, I am a little confused. What is the difference between the regex character * and +.
It is not clear from the example, Any resource where I can study this?

Your code so far

let chewieRegex = /change/; // Only change this line
let result = chewieQuote.match(chewieRegex);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36.

Challenge: Match Characters that Occur Zero or More Times

Link to the challenge:

plus + sign to look for characters that occur one or more times. There’s also an option that matches characters that occur zero or more times. The character to do this is the asterisk or star: * .

This is from the challenge description? :point_up:

I know that is what is written there, I do not understand howone or more times differs from zero or more times. My question is in what cases can you use + sign as opposed to * sign because they seem to be giving similar results

Ok, I got it. Consider example:

const plusRe = /2+/;
const starRe = /2*/;

plusRe.test('12'); // true ('2' presented 1 or more times)
starRe.test('12'); // true ('2' presented 0 or more times)
plusRe.test('13'); // false ('2' presented 0 times, whereas we look for one or more times)
starRe.test('13'); // true ('2' presented 0 or more times)
1 Like

Wow now I feel silly for not understanding this. Thank you sooooo much