when you have a character class in a regular expression and you put a caret as first character, it is matching anything but the characters inside the character class
so for example if you have
[^aeiou] it will match anything but a vowel
! flip the boolean value
I admit I don’t understand why doing it this way
also because you need to test the first string, not the second
but the reason the test method is like that is because if you use
[^aeiou] in a regular expression it will match if there is none of the vowels, but if you use
[aeiou] it will match if there is any of the vowels
so the test method gives true if none of the letters are included in the other string, and false if any is included. flipping this with
! you get false if any of the letters are included, and false if they are not included.
ah, ok, with this explanation I also get why it is done in this way.
the regular expression is
/[^hello]/i , when “hey” is tested it returns
true because the y is not a character included in the other string. so the function returns