DEV Community

Discussion on: Can you find the bug in this piece of code? - RegExp edition 🌍

Collapse
 
siddharthshyniben profile image
Siddharth

Just remove the g flag to fix

Collapse
 
nombrekeff profile image
Keff

There you go, you found it!! Kinda weird if you don't expect that behaviour right?

Thread Thread
 
siddharthshyniben profile image
Siddharth

It is! I never knew that till today!

Thread Thread
 
nombrekeff profile image
Keff

Nice that's wonderful! That's what I aim this series to be, so I'm glad you learned something new!

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I also didn't know this. It's probably very useful when building a parser, but when you don't expect it, it's a super confusing error 😖

Thread Thread
 
nombrekeff profile image
Keff

Yup, I was super confused when I first encountered this error. I found it making some unit tests for work, and lost a bit of time trying to figure it out... just for the issue to be a silly little flag xD