nim-regex
nim-regex copied to clipboard
Feature request: Uppercase replacements
I would like to be able to perform an uppercase transform on a regex replacement. For example:
check("STUFFabc".replace(re"STUFF([a-z])([a-z]+)", "\u$1$2") == "Abc")
Basically, I want something like described here
It'd be nice, but in the meantime do this:
import regex
import strutils
proc reTitleCase(m: RegexMatch, s: string): string =
result.add(s[m.group(0)[0]].toUpperAscii)
result.add(s[m.group(1)[0]])
doAssert "STUFFabc".replace(re"STUFF([a-z])([a-z]+)", reTitleCase) == "Abc"