I have an assignment in which I'm supposed to detect whether or not a string is a palindrome. The program is supposed to recognize non-alphanumeric characters and ignore case (eg. "a" and "A" are the same). One of the strings is " ! "
(space, !, space, space) and every time I try to set everything in the string to lower case, the "!" gets completely deleted for some reason. I've tried the following:
String string = " ! ";
string = string.replaceAll("[^a-zA-Z]+","").toLowerCase();
//when converted into an array, the array is empty
Is there a way to handle this case? Many thanks!
Edit: from the comments, I just figured out it says "replace anything not in the alphabet". Sorry about that. I haven't learned a lot about regexes yet, so my bad.