WoNáDo
6/29/2006 9:58:00 PM
I've recognized an additional problem, which might come from wrong
expectations.
A short program:
palindrome = [ "rr",
"rer",
"reer"]
palindrome.each do |text|
if (md = text.match(/^(?<o>|.|(?:(?<i>.)\g<o>\k<i>))$/))
puts "'#{text}' is a palindrome"
puts md[1]
puts md[2]
else
puts "no match for '#{text}'"
end
end
Results in:
'rr' is a palindrome
rr
r
'rer' is a palindrome
rer
r
no match for 'reer'
I'm surprised that named groups, that are defined inside a named group a
like "global references". Is there a possibility to change this behaviour,
that "\k<i>" refers to the associated "(?<i>.)" in the actual recursive call
(like "local variables").
Best regards, Wolfgang Nadasi-Donner