2

I'd like to replace Context in myAppContext and upper case on tab pressing, so the end result should be MyApp.

I would rather do it all at once. Here's where I started.:

To remove 'Context' I can do ${1/Context//} and for uppercase: ${1/(^[a-z])/${1:/upcase}/}.

What is the best way to combine these two?

Mark
  • 143,421
  • 24
  • 428
  • 436
cyrus-d
  • 749
  • 1
  • 12
  • 29

2 Answers2

2

You can use

${1/^([a-z])|Context/${1:/upcase}/g}

See the regex demo.

Here, ^([a-z])|Context matches either a lowercase ASCII letter at the start of the string (capturing it into Group 1) or a Context substring, and replaces the match with the uppercased Group 1 value (which will be empty if Context matches.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
2

Using the capitalize transform this is very easy:

${1/(.*)Context/${1:/capitalize}/}

Just capitalize everything before Context - capitalize only works on the first letter anyway. No need for a g flag.

Mark
  • 143,421
  • 24
  • 428
  • 436