# Ultisnips capital and lower character in same snippet

I am trying to expand my snippets. I use Ultisnips.

ofcourse, I can have

snippet 'a "greek alpha" A
\alpha
endsnippet


and

snippet 'A "greek alpha" A
\Alpha
endsnippet


and both works fine. But, I am looking for something like

snippet '[aA] "greek alpha" A
\[aA]lpha
endsnippet


i.e. if I put 'a, I will get \alpha, with 'A, I will get \Alpha from same snippet. Is this possible?

Yes, it's possible to use parts of the snippet trigger in the output, but it's not as simple as using a matching character class on each side.

To correctly configure this, you need to use an r flag to use a regular expression in the trigger, use a capturing group inside parens for the character class (the trigger needs to be inside quotes as well.)

And then in the expansion you need to use a Python block and access the match object to get the contents of the capture group.

This snippet does it:

snippet "'([aA])" "greek alpha" rA
\\!p snip.rv = match.group(1)lpha
endsnippet

• Ah! Much ado about a little thing. I will skip that. Jan 29 at 15:18