How to convert filename like Account-Manager.hpp to __ACCOUNT_MANAGER_HPP__ in VSCode snippets?

14 Views Asked by At

I am trying to write a VScode snippet to convert the filename to a unique string so that it can be used in the header's include pragma.

For example, if the filename is Account-Manager.hpp then I want to convert it into __ACCOUNT_MANAGER_HPP__.

To covert filename to all caps, "${TM_FILENAME/(.*)/${1:/upcase}/}",

To replace all - and . to _, "${TM_FILENAME/(.*)/${1:/upcase}/}",

Not able to combine two regexes into a single one!

Answer: __${TM_FILENAME/(^|[-.])([^-.]+)/${1:+_}${2:/upcase}/g}__"

Reference: vscode snippet - transform and replace filename

1

There are 1 best solutions below

0
pitnal On

Found the solution as below:

The double operation can be done with multiple captures as below: __${TM_FILENAME/(^|[-.])([^-.]+)/${1:+_}${2:/upcase}/g}__"