Write a function to detect if a string is a palindrome, handling edge cases such as spaces and special characters.