我正在解决http://www.rubeque.com/problems/a-man-comma--a-plan-comma--a-canal--panama-excl-/solutions,但我在处理#{}作为regexp中的评论时感到有点困惑。 我的代码看起来现在这个样子Ruby:Rubeque:正则表达式中的变量?
def longest_palindrome(txt)
txt[/#{txt.reverse}/]
end
我试图txt[/"#{txt.reverse}"/]
或txt[#{txt.reverse}]
但没有任何工程如我所愿。我应该如何将变量与正则表达式相关联?
你有正确的第一次。 – pguardiario