DEV Community

Discussion on: Why this regex it's not working properly? [solved]

Collapse
 
ghaerdi profile image
Gil Rudolf Härdi

Thanks for the advise, what I really need is to know what happened with my code.

What is the reason for not output watermelon?

But somehow your code is very helpful, you used match and it worked well so my question has changed to why test don't worked but match yes?. This time I found the info that I want:
The RegEx object has a property called lastIndex updated with test method, that property don't reset when test returns true. If the same regex is used again then can happen what happened with my code.

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

@ghaerdi I have explained this weird behavior of test method in my this article.