nim-regex icon indicating copy to clipboard operation
nim-regex copied to clipboard

Feature request: Uppercase replacements

Open jyapayne opened this issue 6 years ago • 1 comments

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

jyapayne avatar Oct 10 '19 22:10 jyapayne

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"

nitely avatar Oct 11 '19 05:10 nitely