In Ruby there is a way to replace occurences of a given regular expression with the value returned by a callback.
For example:
s.gsub(/^\d+(\w+)\d+/) {
|m| m.upcase
}
which basically takes every "word", surrounded by digits, passes it to the callback function, gets it uppercased and replaces the original.
How can I do something like that in Nim?
Definitely spend some time reading through the docs for nre, I haven't used it much but was able to cobble this together
import nre,strutils
proc upcase(r:RegexMatch):string = r.captures[0].toupperAscii()
let input = "4four4 score and 7seven7"
echo replace(input,re"\d+(\w+)\d+",upcase) #FOUR score and SEVEN
I also don't know ruby but I think that's what you're going for, for each match, replace it with the captured (w) raised to upper case
If you want to leave the numbers in there, the callback would return r.match.toUpperAscii() instead