Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Code-Snippets transform: downcase and capitalize at the same time

I have this:

${1/([A-Z]*)(?:_)([A-Z]+)*/${1:/downcase}${2:/downcase}/g}

How to make use downcase and capitalize on the same (2) group?

${1/([A-Z]*)(?:_)([A-Z]+)*/${1:/downcase}${2:/downcase/capitalize}/g}

I want to tansform ZXC_ASD to zxcAsd.

like image 719
lukaszpolowczyk Avatar asked Jul 10 '18 19:07

lukaszpolowczyk


Video Answer


1 Answers

Try it like this:

"camelCaseSnail": {
"scope": "javascript,typescript",
    "prefix": "log",
    "body": "${1/([A-Z]*)(?:_)(?:([A-Z])([A-Z]+))*/${1:/downcase}${2:/capitalize}${3:/downcase}/g}"
}

enter image description here

Basically, I've changed the second capture group ([A-Z]+)* to a non-capture group that has two inner capture groups (?:([A-Z])([A-Z]+))*, a single letter for camel-case and the rest, which I refer in the replace/transform part: /downcase}${2:/capitalize}${3:/downcase}/

like image 193
wp78de Avatar answered Sep 22 '22 15:09

wp78de