Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Uppercase replacements #44

Open
jyapayne opened this issue Oct 10, 2019 · 1 comment
Open

Feature request: Uppercase replacements #44

jyapayne opened this issue Oct 10, 2019 · 1 comment

Comments

@jyapayne
Copy link

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

@nitely
Copy link
Owner

nitely commented Oct 11, 2019

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants