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.
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 whytest
don't worked butmatch
yes?. This time I found the info that I want:The
RegEx
object has a property calledlastIndex
updated withtest
method, that property don't reset whentest
returnstrue
. If the same regex is used again then can happen what happened with my code.@ghaerdi I have explained this weird behavior of test method in my this article.