/(^.*\z)(?(?{ $+ eq reverse $+ })|(?!))/s
####
/
( # capture group
^ # match begin of string
.* # match everything
\z # match end of string
)
(? # if
(?{ $+ eq reverse $+ }) # $+ (last captured group) is palindrome
# then match nothing (succeed)
| # else
(?!) # fail on matching nothing (fail the regex)
)
/xs # x for readability, s to make . match \n
# Note: can match empty string
####
rule palindrome {
$foo := (\w+) ::: { fail if $foo ne reverse $foo }
}
# Note: doesn't match empty string
####
/(.+)(??{ reverse $+ })/s
####
/
(.+) # match one or more characters
(??{ quotemeta reverse $+ }) # match the reverse of what was matched
/xs
# Note: doesn't match empty string or single character string
####
rule palindrome {
$foo := (\w+) <{ quotemeta reverse $foo }>
}