Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
\b(?|([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])\6\5\4\3\2\1|([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])[A-Za-z]\5\4\3\2\1|([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])\5\4\3\2\1|([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])[A-Za-z]\4\3\2\1|([A-Za-z])([A-Za-z])([A-Za-z])([A-Za-z])\4\3\2\1|([A-Za-z])([A-Za-z])([A-Za-z])[A-Za-z]\3\2\1|([A-Za-z])([A-Za-z])([A-Za-z])\3\2\1|([A-Za-z])([A-Za-z])[A-Za-z]\2\1|([A-Za-z])([A-Za-z])\2\1|([A-Za-z])[A-Za-z]\1)\b
/
g

Description

How to detect palindromes up to 12 characters in length. I chose 12 because currently, the longest palindrome that is an actual word is "tattarrattat".

This was a fun exercise because someone said pcre can't detect palindromes. Check and mate, my good sir.

Submitted by Damian Torres - 7 years ago