#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?ix)(?(DEFINE)" & @CRLF & _
" (?<palindrome>" & @CRLF & _
" # Recursive alternative first to match recursive palindromes." & @CRLF & _
" # Invert alternatives order to match nested palindromes individually" & @CRLF & _
" # and (drastically) reduce backtracking." & @CRLF & _
" (?<l1>\p{L})\p{M}* [\s\p{P}]* (?&palindrome) [\s\p{P}]* \k<l1>\p{M}*" & @CRLF & _
" | (?<l2>\p{L})\p{M}* [\s\p{P}]* \k<l2>\p{M}*" & @CRLF & _
" | \p{L}\p{M}*" & @CRLF & _
" )" & @CRLF & _
")" & @CRLF & _
"" & @CRLF & _
"(?<=[\s\p{P}]|^) (?&palindrome) (?(?=\s*\p{P}) (?:\s*\p{P})+ | (?=\s|$))"
Local $sString = "~ should not match" & @CRLF & _
"jambon" & @CRLF & _
"" & @CRLF & _
"~ Simple" & @CRLF & _
"a" & @CRLF & _
"bb" & @CRLF & _
"cc" & @CRLF & _
"ddd" & @CRLF & _
"bob" & @CRLF & _
"ara" & @CRLF & _
"abbb a" & @CRLF & _
"radar" & @CRLF & _
"essayasse" & @CRLF & _
"" & @CRLF & _
"~ Spaces, diacritics and punctuation" & @CRLF & _
"Don't nod!Step on no pets." & @CRLF & _
"Ésope reste ici et se repose." & @CRLF & _
"Élu par cette crapule ! ?" & @CRLF & _
"Tu l'as trop écrasé, César, ce Port-Salut !" & @CRLF & _
"Zeus a été à Suez." & @CRLF & _
"" & @CRLF & _
"~ Recursive palindromes" & @CRLF & _
"a a !" & @CRLF & _
"ah ha !" & @CRLF & _
"abba / ab b a" & @CRLF & _
"~" & @CRLF & _
"abba été àb ba" & @CRLF & _
"~" & @CRLF & _
"abba, ab b a, abbà été àb ba"
Local $sSubst = "[$0]"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm