[Question]
  [
A *palindrome* is some string that is spelled the same way both backwards and forwards. For instance, 'Eva, can I stab bats in a cave?' is a palindrome (EVACANISTAB | BATSINACAVE)
For this code golf, using the language of your choice, determine if a given string is a palindrome or not.
*Edge Cases:*
* Punctuation is not counted towards palindrominess.
* Control characters are not counted towards palindrominess.
* Whitespace is not counted towards palindrominess.
* Numbers are counted towards palindrominess.
* Case in this challenge is not counted towards palindrominess.
* There is no limit to the length of strings to evaluate, except for what is imposed by your language of choice.
* For this challenge, limit yourself to the ASCII character set.
*Technical Requirements:*
* Only method bodies are needed; additional things like method signatures, data structure declarations, etc. do not count towards the victory requirement.
* Code must compile or interpret without compile-time errors or exceptions.
* Code must not throw any unhandled exceptions or crash. (Almost needless to say. Almost.)
* Code must return some value indicating palindrominess. The data type depends on the language you use (e.g. a C# user might use a `bool`, whereas a JavaScript user could use a `var`.)
* You may not write your own interpreter that performs this task as a 'native' capability so you can 'golf' a near-winning score. (Hopefully needless to say.)
*Victory Condition:*
* The shortest code in characters wins.
# *Current Leader: tmartin (k, 25 characters)*
...Want the magic green check mark by *your* answer? Beat this guy's answer!
  
[Answer]
## K, 25
```
{x~|x:_x@&x in,/.Q`a`A`n}
```
.
```
k){x~|x:_x@&x in,/.Q`a`A`n}"Eva, can I stab bats in a cave?"
1b
```
[Answer]
## Perl, 26 char
```
s/_|\W//g;uc eq reverse uc
```
Evaluates to 1 when `$_` is a palindrome, `""` (one of Perl's false values) when it is not.
Sample usage:
```
sub palin {
    s/_|\W//g;uc eq reverse uc
}
while (<DATA>) {
    chomp;
    print "$_ => ",palin()?"yes":"no","\n";
}
__DATA__
Eva, can I stab bats in a cave?
A man, a plan, a canal. Panama!
Madam, I'm Adam Carolla.
757
Boeing 757
A man, a plan, a big shovel, a canal. Panama!
A man, a plan, a canoe, pasta, heros, rajahs, a coloratura, maps, snipe, percale, macaroni, a gag, a banana bag, a tan, a tag, a banana bag again (or a camel), a crepe, pins, Spam, a rut, a Rolo, cash, a jar, sore hats, a peon, a canal >> __Panama__
```
output:
```
Eva, can I stab bats in a cave? => yes
A man, a plan, a canal. Panama! => yes
Madam, I'm Adam Carolla. => no
757 => yes
Boeing 757 => no
A man, a plan, a big shovel, a canal. Panama! => no
A man, a plan, a canoe, pasta, heros, rajahs, a coloratura, maps, snipe, percale, macaroni, a gag, a banana bag, a tan, a tag, a banana bag again (or a camel), a crepe, pins, Spam, a rut, a Rolo, cash, a jar, sore hats, a peon, a canal >> __Panama__ => yes
```
[Answer]
### C# 82 only :)
```
var x=s.ToLower().Where(char.IsLetterOrDigit);return x.SequenceEqual(x.Reverse());
```
Couldn't resist the temptation of writing a boilerplate-free program in my favorite language.
A test is available here: <http://ideone.com/8bwz7z>
[Answer]
### GolfScript, ~~36 34 31~~ 30 characters
```
{0"0:A[a{"@{>^}+/},{32|}%.-1%=
```
Similar algorithm to [my previous (Javascript) solution](https://codegolf.stackexchange.com/a/11158/7209).
`0"0:A[a{"@{>^}+/` -- Optimised by Peter Taylor and Howard. My version was `"/9@Z"{1$<},,2%\;`. Howard donated function concatenation and Peter Taylor donated XOR for modulo-2. It's basically a generic method of comparing if the value is in a sequence of ranges.
`{.96>32*-}%` (11 characters) is not really an improvement over Javascript's `.toUpperCase()` (14 characters), especially since it mangles some weird punctuation that follows `z` in the ASCII table (which doesn't matter here).
as Peter Taylor's suggested, however, if we filter out alphanumerics first, we can convert to lowercase and digits just by setting one bit in each character: `{32|}`
`.-1%=` does all the palindromic heavy lifting. One part I'm not really fond of is how long it took me to find out how to reverse an array. I should have read the docs. The other two characters perform stack management and comparison.
Test: <http://golfscript.apphb.com/?c=IkV2YSwgY2FuIEkgc3RhYiBiYXRzIGluIGEgY2F2ZT8iCgp7IjA6QVtheyJcez59KywsMiV9LHszMnx9JS4tMSU9>
---
Further, if I can assume that none of the following control characters are present: (Data link escape, device control 1-4, negative acknowledge, synchronous idle, end of transmission block, cancel, end of medium) (we all agree these are all pretty obscure) or if I can treat them as uppercase versions of the digits 0-9, we can save another two characters:
## GolfScript, 28 characters
```
{32|}%{0"0:a{"@{>^}+/},.-1%=
```
Test: <http://golfscript.apphb.com/?c=IkV2YSwgY2FuIEkgc3RhYiBiYXRzIGluIGEgY2F2ZT8iCgp7MzJ8fSV7MCIwOmF7IkB7Pl59Ky99LC4tMSU9>
[Answer]
### Javascript, 53 characters:
```
(x=x.toLowerCase().match(/[a-z\d]/g))+""==x.reverse()
```
is a javascript expression that evaluates to true if `x` is a palindrome, to false if it isn't. It assumes `x` is a string. If that's not guaranteed, prepend `x+="",`
Here's a breadcrumb: Due to how `reverse()` works,
```
(x=x.toLowerCase().match(/[a-z\d]/g))==""+x.reverse()
```
fails. However,
```
""+(x=x.toLowerCase().match(/[a-z\d]/g))==x.reverse()
```
is perfectly fine.
[Answer]
# Bash: ~~52~~ ~~48~~ 46 characters
```
s=${1,,};s=${s//[^a-z0-9]};[ $s = `rev<<<$s` ]
```
This takes the sting to check as first parameter and sets the exit code to 0 for palindrome and 1 for not.
Sample run:
```
bash-4.2$ p() { s=${1,,};s=${s//[^a-z0-9]};[ $s = `rev<<<$s` ]; }
bash-4.2$ p 'Eva, can I stab bats in a cave?'; echo $?
0
bash-4.2$ p 'A man, a plan, a canal. Panama!'; echo $?
0
bash-4.2$ p "Madam, I'm Adam Corolla."; echo $?
1
bash-4.2$ p '757'; echo $?
0
bash-4.2$ p 'Boeing 757'; echo $?
1
bash-4.2$ p 'A man, a plan, a shovel, a canal. Panama!'; echo $?
1
bash-4.2$ p 'A_man,_a_plan, a_caremer, a canal:_Panama!'; echo $?
0
```
[Answer]
**Python 2: 49** (without counting the method signature)
```
def f(s):
 s=filter(str.isalnum,s.upper())
 return s==s[::-1]
```
A complete program, with input and output can be writte in **74** characters.
```
import sys
s=filter(str.isalnum,sys.stdin.read().upper())
print s==s[::-1]
```
Example usage:
```
$echo 'Eva,can I stab bats in a cave?' | python palindrome.py
True 
$ cat huge_palindrome.txt | python palindrome.py
True
$echo 'Able was I ere i SaW elBa' | python palindrome.py                                                                   
True                                         
```
(`huge_palindrome.txt` contains [this](http://norvig.com/pal17txt.html) 17,826 word palindrome)
This solution can be adapted to python 3 adding some characters:
**Python 3: 55**
```
def f(s):
 s=list(filter(str.isalnum,s.upper()))
 return s==s[::-1]
```
[Answer]
## R: 66
```
w=grep("[a-z0-9]",strsplit(tolower(s),"")[[1]],v=T);all(w==rev(w))
```
Usage:
```
f=function(s){w=grep("[a-z0-9]",strsplit(tolower(s),"")[[1]],v=T);all(w==rev(w))}
f("Eva, can I stab bats in a cave?")
[1] TRUE
```
[Answer]
**JAVA (or the most verbose language ever), ~~102~~ ~~96~~ 95 char**
```
s=s.replaceAll("\\W|_","");return s.equalsIgnoreCase(new StringBuffer(s).reverse().toString());
```
Usage (with ungolfed code): 
```
static boolean q(String s) {
    s=s.replaceAll("\\W|_","");
    return s.equalsIgnoreCase(new StringBuffer(s).reverse().toString());
}
public static void main(String[] args) {
    System.out.println(q("'A man, a plan, a canal - Panama!'"));
}
```
Shortened with the help of the commenter below
[Answer]
# Mathematica ~~54~~ 53
One byte saved thanks to CatsAreFluffy:
```
PalindromeQ@StringCases[ToUpperCase@#,WordCharacter]&
```
For those with version 10.2 or earlier:
```
#==Reverse@#&@StringCases[ToUpperCase@#,WordCharacter]&
```
**Example**
```
PalindromeQ@StringCases[ToUpperCase@#, WordCharacter]&["Eva,can I stab bats in a cave?"]
```
> 
> True
> 
> 
> 
[Answer]
## J, 30 characters
```
*/(=|.)tolower(#~'[^_\W]'rxE])
```
Usage:
```
   */(=|.)tolower(#~'[^_\W]'rxE])'A man, a plan, a canal - Panama!'
1
   */(=|.)tolower(#~'[^_\W]'rxE])'Doc, note: I dissent. A fast never prevents a fatness. I diet on cod'
1
```
[Answer]
# k (~~50 48 45~~ 38 chars)
Suppresses all errors, returning a default of `0b` (false).
```
{X~|X@:&(X:_:x)in 10h$(48+!10),97+!26}
```
Example:
```
k){X~|X@:&(X:_:x)in 10h$(48+!10),97+!26} "Eva, can I stab bats in a cave?"
1b
```
edit: shaved three more character by avoiding intermediate variable. H/T, CS. -7: No need to suppress errors.
[Answer]
# Ruby: ~~43~~ 38 characters
```
s=s.upcase.tr'^A-Z0-9','';s==s.reverse
```
Sample run:
```
irb(main):001:0> p=->s{s=s.upcase.tr'^A-Z0-9','';s==s.reverse}
=> #<Proc:0x854592c@(irb):1 (lambda)>
irb(main):002:0> p['Eva, can I stab bats in a cave?']
=> true
irb(main):003:0> p['A man, a plan, a canal. Panama!']
=> true
irb(main):004:0> p["Madam, I'm Adam Corolla."]
=> false
irb(main):005:0> p['757']
=> true
irb(main):006:0> p['Boeing 757']
=> false
irb(main):007:0> p['A man, a plan, a shovel, a canal. Panama!']
=> false
irb(main):009:0> p['A_man,_a_plan, a_caremer, a canal:_Panama!']
=> true
```
[Answer]
# C++, ~~107~~ (miscounted), ~~100~~ (miscounted), 81
```
string s;for(int c:t)if(isalnum(c))s+=c|32;return s==string(s.rbegin(),s.rend());
```
* Exploits ASCII bit patterns.
* Relies on an evil `using namespace std;`.
* Uses bitwise AND and OR instead of the logical operators.
* Uses `int` because it's shorter than `char` or `auto`.
```
#include <string>
using namespace std;
bool IsPalindrome(const string & t) {
string s;for(int c:t)if(isalnum(c))s+=c|32;return s==string(s.rbegin(),s.rend());
}
#include <cassert>
int main() {
    assert(!IsPalindrome("gorilla"));  // simple failure
    assert( IsPalindrome("racecar"));  // simple success
    assert( IsPalindrome("Hannah"));   // case blind
    assert(!IsPalindrome("1999"));     // digit failure
    assert( IsPalindrome("2002"));     // digit success
    // Ignore spacing, punctuation, and case:
    assert( IsPalindrome(" \t09AZ/:@[`{za90"));  // boundaries
    assert( IsPalindrome("A man, a plan, a canal: Panama."));
    assert( IsPalindrome("Eva, can I stab bats in a cave?"));
    assert( IsPalindrome(""));  // empty string
    return 0;
}
```
[Answer]
# Lua, 56
```
a=io.read"*l":lower():gsub("%W","")print(a:reverse()==a)
```
[Answer]
**Python 3/2 59 chars:**
```
def pld(i):
   p=[c for c in i.lower() if c.isalnum()]
   return(p == p[::-1])
```
[Answer]
# Haskell, 43
Using the standard libraries `Control.Monad`, `Control.Monad.Instances`, and `Data.Char`:
```
ap(==)reverse.map toLower.filter isAlphaNum
```
[Answer]
**PHP 60 characters.**
First try on codegolf.
```
//thank you manatwork
echo($x=preg_replace('/\W/','',strtolower($c)))==strrev($x); 
```
Example:
```
$c='Eva, can I stab bats in a cave?';
echo($x=preg_replace('/\W/','',strtolower($c)))==strrev($x);
//prints 1
```
[Answer]
**Python 2 64 Charecters:** 
```
i =''.join(re.findall('[a-z0-9]+',i.lower()))
return i==i[::-1]
```
[Answer]
# Haskell 48
```
(\x->x==reverse x).map toLower.filter isAlphaNum
```
used like this:
```
(\x->x==reverse x).map toLower.filter isAlphaNum$"Eva, can I stab bats in a cave?"
```
[Answer]
**Smalltalk**, Squeak/Pharo flavour  
**116** chars using traditional formatting with tabs
You add two methods to String:
```
selffles
    ^self = self reverse
isPalindrome
    ^(self asUppercase asDecomposedUnicode select: #isAlphaNumeric) selffles
```
We could of course eliminate some spaces, or use shorter method names, but let's not betray the spirit of Smalltalk.
More over, this will handle French palindromes, like in <http://fr.wikipedia.org/wiki/Liste_de_palindromes_fran%C3%A7ais>, not many answers in this page can.
```
['Léon a trop par rapport à Noël' isPalindrome] assert.
```
[Answer]
# Python 3 (51 char)
### and may be Python 2
based on *abhiram* solution (with more agressive golfing)
```
from re import findall
def palindrome(i):
 i=findall('[a-z\d]',i.lower())
 return i==i[::-1]
print(palindrome(input('Phrase: ')))
```
may be shortened to 46 chars, using RE '\w'
and variant with extremely shortened function body (27 chars)
```
import re
l=str.lower
f=re.compile('[a-z\d]').findall
def palindrome(i):i=f(l(i));return i==i[::-1]
print(palindrome(input('Phrase: ')))
```
[Answer]
# [Julia 1.0](http://julialang.org/), 63 bytes
```
~s=((x=filter(in(['0':'9';'A':'Z']),uppercase(s)))==reverse(x))
```
[Try it online!](https://tio.run/##TYqxDoIwFEVn@YoXlrYJMQ@VQU2jDg5uzhqH11pjDRbSAjLx65XF4HTPObmvtrSU9zEOQXLey4ctG@O5dfzKkG3Ymm3ZYdwLu4msrWvjNQXDgxBCSm8640frhYj78Kw@MKTHjjLQ5OAEoSEFipoA1gGNsTO7NPkdz1Rad/fV20ytyBARcI5YTDFfLFd/OhEpDTDTitIkfgE "Julia 1.0 – Try It Online")
Since punctuation is filtered out, `"5,000 0.005"` is considered a palindrome.
[Answer]
## Windows PowerShell, 56 47 45 chars
Updated (see comments), and can remove the brackets around the regex:
```
($s=$s-replace'\W')-eq(-join$s[$s.length..0])
```
Original (56)
```
$s=$s-replace'[^\w]','';$s-eq($s[-1..-$s.length]-join'')
```
Original Un-golfed:
```
$s = "Eva, can I stab bats in a cave?"
$s = $s -replace '[^\w]', ''
$rev = $s[-1..-$s.length] -join ''
$s -eq $rev
```
[Answer]
# C++, 74 bytes
This code is actually really elegant, and easy to understand (when formatted correctly). I don't believe it's possible to get any shorter in C++, and it doesn't use any standard library functions. 
```
p(auto c){auto e=c;while(*e)++e;--e;while(*e==*c&e>c)--e,++c;return e<=c;}
```
Example usage: 
```
p("Hello"); //Outputs 0
p(""); //Outputs 1
p("a"); //Outputs 1
p("HellolleH"); //Outputs 1
```
Nicely formatted version:
```
p(auto c)
{
    auto e=c;
    while(*e) ++e;
    --e;
    while(*e==*c & e>c)--e,++c;
    return e<=c;
}
```
[Answer]
# PHP, ~~26 84 80 78 62~~ 63 bytes
```
<?=strrev($s=strtolower(preg_replace("#\W#","",$argv[1])))==$s;
```
takes input from first command line argument; prints `1` for truthy, empty string for falsy.
---
I18n is a littly expansive, as there is no multibyte alternative for `strrev` (110 bytes; run with `-r`):
```
preg_match_all("#.#us",$s=strtolower(preg_replace("#\W#u","",$argv[1])),$m);echo$s==join(array_reverse($m[0]);
```
utf8\_strrev blatantly [stolen from the PHP manual](http://php.net/manual/en/function.strrev.php#83461). You might also want to take a look at [this blog post](http://kvz.io/blog/2012/10/09/reverse-a-multibyte-string-in-php/).
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 18 bytes
```
#|:\(2!"0:a{"')__:
```
[Try it online!](https://ngn.codeberg.page/k#eJyFUE1PwkAQve+vGKuJkNDWtnDZHgyJHrwY70hgaKewod3F3ZFAUH+7Uwx69LJv533M7E6jrz/06yC/iu40nqLb4WKhlWJ9upkdv7xuAOBQLt22HCwbNG15KI+lH84/xTOLHvc4ggotPEFgXMEKOYCxgELu6T4qs3lve3Ys1A5bY2vvul7Iz8IUOrSjXmt/UHphq+FFoMNL/MFVI7COScuc2oRAlhOYQoOBwdKePOy8gJXhKCxbCiE5e4nBWahcfemV5UWeXQpELIpCzl9iPD4/TaVqw7wLOk0lS2vXNol8sNrSodqgXVNSuS59e6fAxtmQZlk2maRh4zwLFfeZmF1cE5PvjKXYNDHGgb2x69gEuf8tQ6l/16jUN9xbhXo=)
Uses @scrawl's suggestion [here](https://codegolf.stackexchange.com/questions/11155/shortest-code-to-determine-if-a-string-is-a-palindrome?page=2&tab=modifieddesc#comment463731_11166) to return `1` for palindromes and `2` for non-palindromes. If `1` and `0` are required, the solution can be adjusted by prefixing `1=`.
* `_:` lowercase the (implicit) input
* `(...)_` filter out values where the code in `(...)` returns a non-0 value
	+ `2!"0:a{"'` do a bins lookup, then mod the result by two; returns `0` if the input is within `"a"-"z"` or `"0"-"9"` and `1` otherwise
* `|:\` set up a converge-scan, reversing the input until the original input is returned. on palindromes, returns a one-item list; on non-palindromes, a two-item list
* `#` take the count of the result from above. As noted, if a strict `1` and `0` output are required for palindrome/non-palindrome, prefix `1=` for two bytes
[Answer]
## Ruby, 48
```
p((g=gets.upcase.gsub /[^A-Z\d]/,'')==g.reverse)
```
Quite simple, and hastily made so not golfed too much. I shall golf it more later.
[Answer]
# [Pylongolf2](https://github.com/lvivtotoro/pylongolf2), 24 bytes
```
c╨2"[^a-zA-Z]"-_╨1=~
```
`c` takes the input, `╨2` to convert to lower case.  
I then push a regex onto the stack and use `-` to remove all non-alphabetical characters in the input.  
`_` duplicates the input.  
`╨1` reverses it and `=` then compares them.  
`~` prints the stack in the end which prints either `true` or `false`. 
[Answer]
# PowerShell, ~~194~~ 190 bytes
A recursive implementation to show how an unnamed PowerShell scriptblock can call itself.
```
$P={param([string]$s)$s=($s-replace'[^a-z]').tolower();if(!$s){return $true};if($s.length-lt4){return $s[0]-eq$s[-1]};$s[0]-eq$s[-1]-and(&$MyInvocation.MyCommand.ScriptBlock $s.trim($s[0]))}
```
ungolfed:
```
$P={
param([string]$s)
$s=($s-replace'[^a-z]').tolower();
if(!$s){return $true};
if($s.length-lt4){return $s[0]-eq$s[-1]};
$s[0]-eq$s[-1]-and(&$MyInvocation.MyCommand.ScriptBlock $s.trim($s[0]))
}
```
tests:
```
&$P "Eva, can I stab bats in a cave?"
&$P "Eva, can I stab cats in a cave?"
&$P "A man, a plan, a canal. Panama!"
&$P "A man, a plan, a big shovel, a canal. Panama!"
&$P "Madam, I'm Adam."
&$P "Madam, I'm Adam Corolla."
&$P "757"
&$P "Boeing 757"
```
]