How to check if a string is a palindrome ignoring case and non-alphanumeric characters in JavaScript

1 Answer

0 votes
function isPalindrome(s) {
    // Remove non-alphanumeric characters and convert to lowercase
    const normalized = s.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
    console.log(normalized);

    return normalized === normalized.split('').reverse().join('');;
}

const s = "+^-Ab#c!D 50...#  05*()dcB[]A##@!$";

console.log(isPalindrome(s));



/*
run:
  
abcd5005dcba
true
  
*/

 



answered Aug 10, 2025 by avibootz
...