This is my code:
const test = "caaaaandy"; const testRegex = /a*/; const result = test.match(testRegex); console.log(result);
[ '', index: 0, input: 'caaaaandy', groups: undefined ]
Why its not this output?
[ 'aaaaa', index: 1, input: 'caaaaandy', groups: undefined ]
Because the description of the * type is :
Matches the preceding item “x” 0 or more times.
And my understanding is, that the a is more than zero times there
When i change the regex to aa* its working. (i know also a+ is working, but i want to specifically wrong with the * type.)