Difference betwen + and * in regular expressions

Hello everyone, I’m finding a bit hard to understand the difference between + and * in regular expressions.
I would be very happy if somebody could make it a bit clearer for me.
Thanks in advance.

1 Like

I don’t really have an example but I know + is for one or more and * is for zero or more. That is the part that I don’t get.

1 Like

Thanks a lot. Can you use this example to make it more clearer?

// example crowd gathering
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
let reCriminals = /C+/; // Change this line
let matchedCriminals = crowd.match(reCriminals);
console.log(matchedCriminals);

why is matchedCriminals = ["CCC"] when /C+/ is used
but when /C*/ is used matchedCriminals = [ "" ]

Everything is much clearer now.
Thanks a lot for your time.:sweat_smile::sweat_smile: