Hi can u please explain why it came out as false
Bello Tomi
1

Hi Bello Tomi —I understand you mean /^a?$/.test("aa") //false

? looks for 0 or 1 match. since a? is the only pattern we have between start ^ and end $ , it’ll match “a” for 0 to 1 occurrence.

/^a?$/.test("") //true - 0 match
/^a?$/.test("a") //true - just 1 match
/^a?$/.test("aa") //false - more than 1 match

If we need “aa” to match, we should go for + instead of ? . hope it helps.

Like what you read? Give Vijayabharathi Balasubramanian a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.