I have a long string input that contains Taiwanese dates. I need to transform them into American notation and leave them in the same exact place of the input. I have created regex that do match against the text in the input but I cannot find the way to transform those matches into integers, do math (to change the year) and then replace the new values in the exact same place where the old values were.
Taiwanese dates are formed as yyy/mm/dd.
For ex: 107年02月13日, that is 02/13/2018
Up to now I have:
input = gets
texto = input.gsub(/\s+/, "")
Date_with_characters = /\d{3}年\d{2}月\d{2}日/
if input.match(Date_with_characters)
puts "Encuentro fechas con caracteres"
elsif
puts "NO encuentro un joraca con caracteres"
end
Date_with_slashes = %r{\d{3}/\d{2}/\d{2}}
if input.match(Date_with_slashes)
puts "Encuentro fechas con barras"
elsif
puts "NO encuentro un joraca con barras"
end
The code above finds all dates (both with characters and slashes) but I was hoping I could then turn the first 3 indexes in the year to integers, do the math to turn it into western calendar, and put it back in the same place (skipping moving year to the end for now). I have had no luck yet and I tried lot of things.
Thanks a lot!