isPalindrome static method

bool isPalindrome(
  1. String text, {
  2. bool caseSensitive = false,
})

Check if string is palindrome

text - The text to check caseSensitive - Whether to consider case (default: false) Returns true if string is palindrome

Implementation

static bool isPalindrome(String text, {bool caseSensitive = false}) {
  String processedText = caseSensitive ? text : text.toLowerCase();
  processedText = processedText.replaceAll(RegExp(r'[^a-zA-Z0-9]'), '');
  return processedText == reverse(processedText);
}