It looks like mine should be fine. I cannot for the life of me figure out why it isn’t working. It says “eye” is a palindrome but “_eye” isn’t. I added the brackets and parentheses and it’s still not working. Another thing is that a capital A by itself is supposed to be a palindrome, but isn’t everything supposed to be in the same case? How are “A” and “eye” supposed to both be palindromes when everything has to be in the same case.
I think you misread the instructions. They said to turn everything to either lower or upper case as a tip to help your algorithm work.
An A is a palindrome because if you look at it from the left it is A and from the right it is A and therefore it is a palindrome.
As for _eye, it is a palindrome because if you ignore the underscore (which they said to ignore when they said to remove all non-alphanumeric characters), the letters are read e, y, e in both directions so it is also a palindrome.
So is it not actually required to make everything the same case in the code? Cause that’s the only way A and eye can both be palindromes. And I understand how _eye would be a palindrome with the right code, the only problem is I don’t know how to remove all non-alphanumeric characters. I’ve tried everything.
You can remove all non-alphanumerics using correct regex pattern. You need a regex pattern that have a character class with alphanumeric characters and you pattern should have a global flag.
Currently you didn’t have the character class in your regex pattern.
You should write the code any way you want but they gave you two tips which were there to help you. Making the strings all lowercase and stripping the non alphanumeric characters before doing the check to see if the string is a palindrome is just common sense.
You can strip the non alphanumeric characters very simply by looping through the string’s characters and checking each one to see if it is a number or letter or not.