14

I want to make snippet for Sublime Text 2 or 3 which will produce the following code:

initial - somename
with upper case - Somename

and somename is text which will be always different.

My draft for this:

<snippet>
    <content><![CDATA[
initial - ${2:somename}
with upper case - ${2:somename}
]]></content>
</snippet>

But how can I uppercase only first letter in parameter?

nktssh
  • 2,171
  • 21
  • 23

1 Answers1

22

Final variant:

<snippet>
    <content><![CDATA[
initial - ${1:somename}
with upper case - ${1/(.+)/\u$1/g}
]]></content>
</snippet>
nktssh
  • 2,171
  • 21
  • 23
  • 1
    Works great for me. I also found these resources helpful. Thought I'd post them here in case anyone else finds them useful: [Sublime Text Unofficial Documentation](http://docs.sublimetext.info/en/latest/extensibility/snippets.html) / [Boost Syntax](http://www.boost.org/doc/libs/1_56_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html) – Kelly Kiernan Apr 05 '16 at 16:41
  • 1
    For me, using Sublime 3, it only works if you catch one character at a time with: `${1/(.)/\u$1/g}` – Lucas Siqueira Jan 14 '18 at 19:36
  • @LucasSiqueira, this will not work as it capitalizes all letters – linuxUser123 Nov 06 '19 at 09:51